【发布时间】:2013-05-21 18:42:01
【问题描述】:
我想使用FOSUserBundle,安装它并首先使用注释设置它,但因为我有其他实体我选择yaml。
我按照文档中的说明进行操作,创建了 yaml 文件并添加了一些我需要的字段。我生成了实体本身,然后在 php 文件中扩展了 BaseUser 类。
这部分工作正常,因为当我第一次想更新 SQL 时,它抛出了更改为受保护或公共的错误,但更新后,基本 FOS 字段不在数据库中。
这里是 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
与第一个相关部分的 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();
}
在我的 ORM config.yml 中,自动映射设置为 true。
【问题讨论】:
标签: php symfony doctrine-orm yaml fosuserbundle