![](/img/trans.png)
[英]Symfony2: fos_user_bundle embedding registration form with entity
[英]FOS user bundle Registration "Entity of type \Entity\User is missing an assigned ID for field 'id'
我已經安裝了FOS user bundle
來管理登錄和注冊功能,但是當我嘗試注冊新用戶時,出現以下錯誤:
Entity of type ****\****\Entity\User 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 FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $id;
這是我的User.orm.yml:
****\****\Entity\User:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
我知道在保留新用戶的數據時會出現問題,但是我不知道如何使Symfony
生成此id
字段。 謝謝!
您的yml
配置錯誤,請嘗試:
type: entity
table: fos_user
fields:
id:
id:
type: integer
generator:
strategy: AUTO
我已經解決了我的問題。 這是我的User.php類:
<?php
namespace *****\*****\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
而且我剛剛刪除了所有YAML
配置文件,這是Annotations和YAML
之間的沖突問題。 現在注冊和登錄工作正常。
您的yml應該看起來像
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
fields:
等等...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.