Php 带yaml的Fos用户包-条令模式更新

Php 带yaml的Fos用户包-条令模式更新,php,symfony,doctrine-orm,yaml,fosuserbundle,Php,Symfony,Doctrine Orm,Yaml,Fosuserbundle,我想使用FOSUserBundle,安装它并首先使用注释进行设置,但因为我有其他实体,所以选择了yaml 我按照文档中写的那样做,创建了yaml文件并添加了一些我需要的字段。我生成了实体本身,然后在php文件中扩展了BaseUser类 这部分工作正常,因为当我第一次想要更新SQL时,它抛出了一个错误,将其更改为protected或public,但在更新之后,基本FOS字段不在数据库中 这是User.orm.yml Plastic\PublicBundle\Entity\User: type:

我想使用
FOSUserBundle
,安装它并首先使用注释进行设置,但因为我有其他实体,所以选择了yaml

我按照文档中写的那样做,创建了yaml文件并添加了一些我需要的字段。我生成了实体本身,然后在php文件中扩展了
BaseUser

这部分工作正常,因为当我第一次想要更新SQL时,它抛出了一个错误,将其更改为protected或public,但在更新之后,基本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();
}
而不是

use FOS\UserBundle\Model\User as BaseUser;
试用

use FOS\UserBundle\Entity\User as BaseUser;

也就是说,因为您使用的是orm,所以必须使用实体基类,而不是模型基类。我也有一段时间遇到了这个问题,但是上面的更改使事情再次正常工作。

尝试过,但没有成功,我认为现在在dev master分支中没有什么区别,因为实体/文档也只是扩展了模型,在fosusrbundle的描述中也提到了sql,mongo使用模型类One您使用的是MongoDB还是ORM?因为你的代码表明你正在使用ORM。。。是的,文档和实体类都在扩展模型。我想这只是为了给它们赋予不同的名称空间,以便库可以确定您使用的方法。我使用的是ORM,但我尝试了您的答案,但没有成功。我设法让它工作起来,就像我在我的yml文件中创建了所有内容一样,然后插入很好,但这不是最好的解决方案,只是一个解决办法。FOS\UserBundle\Entity\User在较新版本的FOS User Bundle中不推荐使用