问题描述
我需要覆盖此Symfony\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\doctrine\model\User.orm.xml文件。
I need to override this Symfony\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\doctrine\model\User.orm.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="FOS\UserBundle\Model\User">
<field name="username" column="username" type="string" length="255" />
<field name="usernameCanonical" column="username_canonical" type="string" length="255" unique="true" />
<field name="email" column="email" type="string" length="255" />
<field name="emailCanonical" column="email_canonical" type="string" length="255" unique="true" />
<field name="enabled" column="enabled" type="boolean" />
<field name="salt" column="salt" type="string" />
<field name="password" column="password" type="string" />
<field name="lastLogin" column="last_login" type="datetime" nullable="true" />
<field name="locked" column="locked" type="boolean" />
<field name="expired" column="expired" type="boolean" />
<field name="expiresAt" column="expires_at" type="datetime" nullable="true" />
<field name="confirmationToken" column="confirmation_token" type="string" nullable="true" />
<field name="passwordRequestedAt" column="password_requested_at" type="datetime" nullable="true" />
<field name="roles" column="roles" type="array" />
<field name="credentialsExpired" column="credentials_expired" type="boolean" />
<field name="credentialsExpireAt" column="credentials_expire_at" type="datetime" nullable="true" />
</mapped-superclass>
</doctrine-mapping>
我需要更改此字段:
<field name="email" column="email" type="string" length="255" />
为此:
<field name="email" column="email_address" type="string" length="255" />
我将getParent方法添加到我的UserBundle中。我已经将Symfony\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\doctrine\model\User.orm.xml
复制到我的
Bundle Symfony\src\Acme\UserBundle\Resources\doctrine\model\User.orm.xml
但是当我更改它时,我看不到效果。我做错了什么?
I add getParent method to my UserBundle. I have copied Symfony\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Resources\config\doctrine\model\User.orm.xmlto myBundle Symfony\src\Acme\UserBundle\Resources\doctrine\model\User.orm.xmlbut when I changed it I do not see the effect. What I am doing wrong?
推荐答案
我已经弄明白了。解决方案是为我先创建FOSUserBundle文档的用户实体添加特殊的注释。
I have figured out. The solution is to add special annotation to User entity which I create earlier form FOSUserBundle documentation.
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email_address", length=255)),
* })
整个课程应该如下所示:
The whole class should look like:
<?php
namespace Acme\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="sf_guard_user")
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="email", column=@ORM\Column(type="string", name="email_address", length=255)),
* })
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
这篇关于Symfony2覆盖User.orm.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!