2016-01-18 11 views
5

सबसे पहले, मुझे पता है कि SO इस तरह के प्रश्नों से भरा है, लेकिन मैंने उन प्रतिक्रियाओं के अनुसार अलग-अलग कॉन्फ़िगरेशन मानों को गठबंधन करने की कोशिश की है।FOSUserBundle: अपरिचित फ़ील्ड: उपयोगकर्ता नामकैनिकल

मैं अपने खुद के उपयोगकर्ता वर्ग के साथ FOSUserBundle उपयोग कर रहा हूँ और जब प्रविष्ट लॉगिन प्रपत्र मैं इस त्रुटि मिलती है:

doctrine: 
     auto_generate_proxy_classes: "%kernel.debug%" 
     naming_strategy: doctrine.orm.naming_strategy.underscore 
     auto_mapping: true 
     # mappings: 
     #  FOSUserBundle: ~ 
fos_user: 
    service: 
     mailer: fos_user.mailer.twig_swift 
    db_driver: orm 
    firewall_name: main 
    user_class: AppBundle\Entity\User 

कुछ बदलाव:

Unrecognized field: usernameCanonical

यहाँ मेरी कोड के कुछ टुकड़े कर रहे हैं परीक्षण में auto_mapping: false और/या असम्बद्ध mappings.FOSUserBundle: ~

यह मेरा उपयोगकर्ता वर्ग है:

<?php 

namespace AppBundle\Entity; 

use Symfony\Component\Security\Core\User\UserInterface; 
use Symfony\Component\Validator\Constraints as Assert; 

use FOS\UserBundle\Model\User as BaseUser; 

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* AppBundle\Entity\User 
* 
* @ORM\Entity 
* @ORM\Table(name="user") 
*/ 
class User extends BaseUser implements UserInterface 
{ 
    const ROLE_DEFAULT = 'ROLE_ADMIN'; 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", length=100) 
    */ 
    protected $name; 

    /** 
    * @ORM\Column(type="string", length=40) 
    * @Assert\Email() 
    */ 
    protected $login; 

    /** 
    * @ORM\Column(type="string", length=255) 
    */ 
    protected $password; 

    /** 
    * @ORM\Column(type="string", length=255) 
    */ 
    protected $salt; 

    /** 
    * @ORM\Column(type="array", length=255) 
    */ 
    protected $roles; 

    /** 
    * Método requerido por la interfaz UserInterface 
    */ 
    public function equals(\Symfony\Component\Security\Core\User\UserInterface $user) 
    { 
     return $this->getLogin() == $user->getLogin(); 
    } 

    /** 
    * Método requerido por la interfaz UserInterface 
    */ 
    public function eraseCredentials() 
    { 
    } 

    /** 
    * Método requerido por la interfaz UserInterface 
    */ 
    public function getUsername() 
    { 
     return $this->getLogin(); 
    } 

    public function __toString() 
    { 
     return $this->getName(); 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set login 
    * 
    * @param string $login 
    */ 
    public function setLogin($login) 
    { 
     $this->login = $login; 
    } 

    /** 
    * Get login 
    * 
    * @return string 
    */ 
    public function getLogin() 
    { 
     return $this->login; 
    } 

    /** 
    * Set password 
    * 
    * @param string $password 
    */ 
    public function setPassword($password) 
    { 
     $this->password = $password; 
    } 

    /** 
    * Get salt 
    * 
    * @return string 
    */ 
    public function getSalt() 
    { 
     return $this->salt; 
    } 

    /** 
    * Set salt 
    * 
    * @param string $salt 
    */ 
    public function setSalt($salt) 
    { 
     $this->salt = $salt; 
    } 

    /** 
    * Get password 
    * 
    * @return string 
    */ 
    public function getPassword() 
    { 
     return $this->password; 
    } 

    /** 
    * Adds a role to the user. 
    * 
    * @param string $role 
    */ 
    public function addRole($role) 
    { 
     $role = strtoupper($role); 
     if ($role === static::ROLE_DEFAULT) { 
      return; 
     } 

     if (!in_array($role, $this->roles, true)) { 
      $this->roles[] = $role; 
     } 
    } 

    /** 
    * Returns the user roles 
    * 
    * Implements SecurityUserInterface 
    * 
    * @return array The roles 
    */ 
    public function getRoles() 
    { 
     $roles = $this->roles; 

     foreach ($this->getGroups() as $group) { 
      $roles = array_merge($roles, $group->getRoles()); 
     } 

     // we need to make sure to have at least one role 
     $roles[] = static::ROLE_DEFAULT; 

     return array_unique($roles); 
    } 

    /** 
    * Set roles 
    * 
    * @param string $roles 
    */ 
    public function setRoles(array $roles) 
    { 
     $this->roles = $roles; 
    } 

    /** 
    * Never use this to check if this user has access to anything! 
    * 
    * Use the SecurityContext, or an implementation of AccessDecisionManager 
    * instead, e.g. 
    * 
    *   $securityContext->isGranted('ROLE_USER'); 
    * 
    * @param string $role 
    * @return Boolean 
    */ 
    public function hasRole($role) 
    { 
     return in_array(strtoupper($role), $this->getRoles(), true); 
    } 

} 

लॉगिन (layout.html.twig वास्तव में) टेम्पलेट ओवरराइड कर दिया गया है और जाहिरा तौर पर सही ढंग से प्रदर्शित, मेरे संस्करण हैं:

  • Symonfy: Symfony संस्करण 2.8.2 - एप्लिकेशन/dev/डिबग
  • "friendsofsymfony/उपयोगकर्ता के बंडल ":"^1.3 "

console doctrine:schema:update मार डाला गया है और यह, किसी भी अधिक परिवर्तन का पता लगाने नहीं है, हालांकि usernameCanonical या ईमेल मौजूद नहीं है डीबी टेबल में।

धन्यवाद

+0

उपरोक्त कोड में कोई 'ईमेल' या' उपयोगकर्ता नाम कैनोनिकल 'संपत्ति/फ़ील्ड नहीं है। – felipsmartins

+0

उन्हें 'बेसयूसर' कक्षा –

+0

बीटीडब्ल्यू से विरासत में प्राप्त किया जाना चाहिए, 'सिद्धांत: स्कीमा: अपडेट' उन क्षेत्रों का पता नहीं लगाता है क्योंकि वे डीबी –

उत्तर

संबंधित मुद्दे