[英]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. 我想使用
FOSUserBundle
,安装它并首先使用注释对其进行设置,但是因为我有其他实体,所以我选择了yaml。
I did as it was written in the documentation, created the yaml file and added some fields that I needed. 我按照文档中的说明进行操作,创建了yaml文件,并添加了一些我需要的字段。 I generated the entity itself and then in the php file extended the
BaseUser
class. 我生成了实体本身,然后在php文件中扩展了
BaseUser
类。
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. 该部分正在工作,因为当我第一次想要更新SQL时,它抛出了将错误更改为protected或public的错误,但是在更新之后,基本FOS字段不在数据库中。
Here is the User.orm.yml 这是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: 还有User.php实体和第一个相关部分:
<?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. 在我的ORM config.yml中,自动映射设置为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. 即,因为您正在使用orm,所以必须使用Entity基类,而不是Model基类。 I got stuck with this a while also, but the above change made things work again.
我也被卡住了一段时间,但是以上更改使事情再次起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.