简体   繁体   中英

Fos UserBundle with yaml - doctrine schema update

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.

Instead of

use FOS\UserBundle\Model\User as BaseUser;

try using

use FOS\UserBundle\Entity\User as BaseUser;

Ie, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM