Jesus M Jesus M - 3 months ago 14
PHP Question

Can't log in extending FOS in Symfony2

I have 3 classes (Auditor, Client and Manager) extending

FOS\UserBundle\Model\User
and several input forms to create every type.

For example, for Auditor class (the other are in the same way):

/**
* @ORM\Entity
* @ORM\Table(name="auditor")
*/
class Auditor extends BaseUser implements NotificationInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;


When I create a new Auditor it works ok, it creates on the auditor table and everything is ok. But when I try to log in it doesn't work. Also, if I see the FOS users by
php app/console app:list-users
command, the new Auditor user does not appear.

What am I doing wrong?

Answer

Although you have extended the classes from BaseUser class, you can't use multiple classes for login in FOSUserBundle. Check your app/config/config.yml file.

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: AppBundle\Entity\User

Here you have defined only one class as a fos_user.

Use PUGXMultiUserBundle for your requirment.

The PUGXMultiUserBundle extends FOSUserBundle adding the feature to handle users of different types.