First of all, I know that SO is full of such questions, but I tried to combine different configuration values according to these answers without any luck.
I use FOSUserBundle with my own User class and when I submit the login form I get this error:
Unrecognized field: username
Here are a few bits of my code:
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
Some tested options include setting auto_mapping: false and / or uncommenting mappings.FOSUserBundle: ~
This is my user class:
<?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; class User extends BaseUser implements UserInterface { const ROLE_DEFAULT = 'ROLE_ADMIN'; protected $id; protected $name; protected $login; protected $password; protected $salt; protected $roles; public function equals(\Symfony\Component\Security\Core\User\UserInterface $user) { return $this->getLogin() == $user->getLogin(); } public function eraseCredentials() { } public function getUsername() { return $this->getLogin(); } public function __toString() { return $this->getName(); } public function getId() { return $this->id; } public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } public function setLogin($login) { $this->login = $login; } public function getLogin() { return $this->login; } public function setPassword($password) { $this->password = $password; } public function getSalt() { return $this->salt; } public function setSalt($salt) { $this->salt = $salt; } public function getPassword() { return $this->password; } public function addRole($role) { $role = strtoupper($role); if ($role === static::ROLE_DEFAULT) { return; } if (!in_array($role, $this->roles, true)) { $this->roles[] = $role; } } public function getRoles() { $roles = $this->roles; foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); }
The input ( layout.html.twig actually) the template has been redefined and appears to display correctly, my versions are:
- Symonfy: Symfony version 2.8.2 - application / dev / debug
- "friendsofsymfony / user-bundle": "^ 1.3"
console doctrine:schema:update was executed and it does not detect any changes, although the username Canal or email does not exist in the database table.
thanks
source share