我在 Symfony2 项目中使用 FosUserBundle 和 SonataUserBundle。
我现在很困惑。我想为实体用户添加字段,但它不起作用。例如,架构没有更新。
这是我的配置:
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
以及添加字段的用户实体,在 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;
}
}
在我的数据库中,表 fos_user_user 似乎是包含用户保存数据的表。
调用“php app/console dictionary:schema:update --force”时不会创建添加的字段(国家、城市...)。如何向用户实体添加字段?我迷失在 fosuserbundle 和 sonatauserbundle....