1
votes

I am new to symfony (symfony2) so i was asked to install sonata admin plus FOSUser bundle to be integrated. Everything went fine, the sonata admin is working fine and the configuration for the fosuser is supposed to be fine as in tuts.

When I go to my terminal and write this command :

php app/console fos:user:create admin [email protected] admin

I get this error

[Doctrine\ORM\ORMInvalidArgumentException]
The given entity of type 'Sonata\UserBundle\Entity\BaseUser' (admin) has no
identity/no id values set. It cannot be added to the identity map.

I have no idea what to do with this error.

2
Does your Sonata User inherit from the FOS User?Fred
I guess yes , this is from my config file fos_user: user_class: Sonata\UserBundle\Entity\BaseUsersizar adam
No, this is just the config that tells FOSUserBundle where to take the user entity from. I think I know what's going on. I'll post the code in an answer.Fred
many thanks @Fred I am very gratefullsizar adam
Dear @fred i have this approach let me try go step by step : in my src folder I have a bundle called Application , inside it you will find Sonata -> UserBundle , in Entity Folder i have to classes Group.php and User.php , what you wrote up i have in the that User.php and in the config.yml the fos_user pointing at this class ... still i get the same errorsizar adam

2 Answers

4
votes

thank you all for helping :)

after mr @fred answer and the help of one of my friends the error is gone and the bundle is working , so do the next if you have the same problem i have :

go to src/Application/Sonata/UserBundle/Entity/User.php add

public function __construct() {
        parent::__construct();
    }

then go to your main config.yml and added this :

fos_user:
    db_driver: orm
    firewall_name: main
    user_class:     Application\Sonata\UserBundle\Entity\User
2
votes

I think the problem is that the FOSUserBundle expects an entity with a Doctrine ID mapping. Try this:

Create an own user class in one of your bundles:

<?php

namespace YOUR\NAMESPACE\YourUserBundle\Entity;

use Sonata\UserBundle\Entity\BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="my_users")
 */
class User extends BaseUser
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
    }
}
?>

Now point the user class to your new entity:

fos_user: 
    user_class: YOUR\NAMESPACE\YourUserBundle\Entity\User