我已经安装了FOS user bundle
来管理登录&注册功能,但是当我尝试注册一个新用户时,我收到以下错误:
Entity of type ********EntityUser is missing an assigned ID for field 'id'.
The identifier generation strategy for this entity requires the ID field to be
populated before EntityManager#persist() is called. If you want automatically
generated identifiers instead you need to adjust the metadata mapping accordingly.
这是我的User.php类:
<?php
// src/Acme/UserBundle/Entity/User.php
namespace ******Entity;
use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORMId
* @ORMColumn(type="integer")
*/
protected $id;
这是我的User.orm.yml:
********EntityUser:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
我知道在持久化新用户的数据时会出现问题,但是我不知道如何让Symfony
生成这个id
字段。谢谢!
您的yml应该看起来像
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
fields:
等等…
您的yml
配置错误,请尝试:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
我的问题解决了。这是我的User.php类:
<?php
namespace **********Entity;
use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity
* @ORMTable(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORMId
* @ORMColumn(type="integer")
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
我刚刚删除了所有YAML
配置文件,这是注解和YAML
之间的冲突问题。现在注册和登录工作正常