sizar adam
sizar adam

Reputation: 61

FOSUser bundle can't create user in command line

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.

Upvotes: 1

Views: 2653

Answers (2)

sizar adam
sizar adam

Reputation: 61

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

Upvotes: 4

Fred
Fred

Reputation: 3362

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

Upvotes: 2

Related Questions