Reputation: 1503
I wanted to use FOSUserBundle
, installed it and first set it up with annotations, but because I had other entities i choose yaml.
I did as it was written in the documentation, created the yaml file and added some fields that I needed. I generated the entity itself and then in the php file extended the BaseUser
class.
That part is working, because when i first wanted to update SQL it threw the error to change to protected or public, but after update, the base FOS fields are not in the DB.
Here is the User.orm.yml
Plastic\PublicBundle\Entity\User:
type: entity
lifecycleCallbacks:
prePersist: [setCreated, setModified]
preUpdate: [setModified]
oneToMany:
albums:
targetEntity: Album
mappedBy: user
images:
targetEntity: Image
mappedBy: user
table: users
id:
id:
type: integer
generator:
strategy: AUTO
fields:
firstName:
type: string
length: 50
lastName:
type: string
length: 50
gender:
type: boolean
dateOfBirth:
type: date
And the User.php entity with the first relevant part:
<?php
namespace Plastic\PublicBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* User
*/
class User extends BaseUser
{
/**
* @var integer
*/
protected $id;
/**
* @var string
*/
private $firstName;
/**
* @var string
*/
private $lastName;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->albums = new \Doctrine\Common\Collections\ArrayCollection();
$this->images = new \Doctrine\Common\Collections\ArrayCollection();
}
In my config.yml for ORM the automapping is set to true.
Upvotes: 1
Views: 939
Reputation: 4842
Instead of
use FOS\UserBundle\Model\User as BaseUser;
try using
use FOS\UserBundle\Entity\User as BaseUser;
I.e, because you're using orm, you have to use the Entity base class, not the Model base class. I got stuck with this a while also, but the above change made things work again.
Upvotes: 2