Symfony2 FosUserBundle和SonataUserBundle:覆盖实体? [英] Symfony2 FosUserBundle and SonataUserBundle : overriding entities?
问题描述
我现在很困惑。我想添加实体用户的字段,但它不工作。没有更新的模式例如。
这是我的配置:
AppKernel:
...
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle(),
new Application\\ \\Sonata\UserBundle\ApplicationSonataUserBundle('FOSUserBundle')
config.yml:
...
#FOSUserBundle配置
fos_user:
db_driver:orm#BDD type
firewall_name:main#firewall name
user_class:Application\Sonata\UserBundle\Entity\User#entity class defined
在app / Application / Sonata / userBundle / Entity /
$ b中添加了字段的用户实体$ b
命名空间Application\Sonata\UserBundle\Entity;
使用Sonata\UserBundle\Entity\BaseUser作为BaseUser;
/ **
*此文件由Sonata EasyExtends软件包生成(http:// sonata- project.org/easy-extends)
*
*参考文献:
*使用对象:http://www.doctrine-project.org/projects/orm/2.0 / docs / reference / working-with-objects / en
*
* @author< yourname> < youremail>
* /
class用户扩展BaseUser
{
/ **
* @var整数$ id
* /
受保护的$ id;
/ **
* @var string
* /
protected $ institution;
/ **
* @var string
* /
protected $ department;
/ **
* @var string
* /
protected $ city;
/ **
* @var string
* /
protected $ country;
/ **
*获取id
*
* @return integer $ id
* /
public function getId()
{
return $ this-> id;
}
/ **
* @return string
* /
public function getInstitution()
{
return $这 - >机构;
}
/ **
* @return string
* /
public function getDepartment()
{
return $这 - >部门;
}
/ **
* @return string
* /
public function getCity()
{
return $这 - >城市;
}
/ **
* @return string
* /
public function getCountry()
{
return $这 - >国家;
}
}
在我的数据库中,表fos_user_user似乎是表使用用户保存的数据。
当调用php app / console doctrine:schema:update --force时,不会创建添加的字段(国家,城市...)。如何向用户实体添加字段?我迷失在fosuserbundle和sonatauserbundle ....
其实看起来我使用fos和奏鸣曲的方式用户捆绑强制我使用XML定义。因此,例如添加一个名为city的字段,您必须添加以下行:
User.php(in / app / Application / Sonata / UserBundle / Entity /):
protected $ city;
User.orm.xml(in / app / Application / Sonata / UserBundle / Ressource / config / doctrine /):
< field name =citycolumn =citytype =text/>
也许把这个在包的文档中将是新手的有趣的);
I use FosUserBundle and SonataUserBundle for my Symfony2 project.
I get confused now. I want to add fields for the entity User but it's not working. There is no update for the schema for example.
Here is my config :
AppKernel:
...
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle(),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle('FOSUserBundle')
config.yml:
...
# FOSUserBundle Configuration
fos_user:
db_driver: orm # BDD type
firewall_name: main # firewall name
user_class: Application\Sonata\UserBundle\Entity\User # entity class defined
And the User entity with added fields, in app/Application/Sonata/userBundle/Entity/
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
/**
* This file has been generated by the Sonata EasyExtends bundle ( http://sonata- project.org/easy-extends )
*
* References :
* working with object : http://www.doctrine-project.org/projects/orm/2.0 /docs/reference/working-with-objects/en
*
* @author <yourname> <youremail>
*/
class User extends BaseUser
{
/**
* @var integer $id
*/
protected $id;
/**
* @var string
*/
protected $institution;
/**
* @var string
*/
protected $department;
/**
* @var string
*/
protected $city;
/**
* @var string
*/
protected $country;
/**
* Get id
*
* @return integer $id
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getInstitution()
{
return $this->institution;
}
/**
* @return string
*/
public function getDepartment()
{
return $this->department;
}
/**
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
}
In my database, table fos_user_user seems to be the table with user saved data.
Added fields (country, city...) are not created when calling "php app/console doctrine:schema:update --force". How to add fields to the user entity ? I'm lost in fosuserbundle and sonatauserbundle....
In fact, it appear that the way i use fos and sonata user bundles force me to use XML definition. So for example adding a field called "city" you have to add these lines :
User.php (in /app/Application/Sonata/UserBundle/Entity/) :
protected $city;
User.orm.xml (in /app/Application/Sonata/UserBundle/Ressource/config/doctrine/) :
<field name="city" column="city" type="text"/>
Maybe putting this in the documentation of the bundles would be interesting for newbies ;)
这篇关于Symfony2 FosUserBundle和SonataUserBundle:覆盖实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!