【发布时间】:2017-05-04 13:47:50
【问题描述】:
我按照这些说明向用户实体添加了一个字段:http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html 但添加的属性没有出现在表单中...
我的类型表格:
<?php
namespace PCUserBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('realName');
}
public function getParent() {
return 'fos_user_registration';
}
public function getName() {
return 'pc_user_registration';
}
}
在应用配置中
fos_user:
db_driver: orm
firewall_name: main
user_class: PCUserBundle\Entity\User
registration:
form:
name: pc_user_registration
我的扩展实体用户
<?php
// src/AppBundle/Entity/User.php
namespace PCUserBundle\Entity;
use FOS\UserBundle\Entity\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;
/**
* @ORM\Column(type="text",nullable=true)
*/
protected $realName;
public function __construct() {
parent::__construct();
// your own logic
}
/**
* Set realName
*
* @param string $realName
*
* @return User
*/
public function setRealName($realName) {
$this->realName = $realName;
return $this;
}
/**
* Get realName
*
* @return string
*/
public function getRealName() {
return $this->realName;
}
}
在我的包的服务文件中:
services:
app.form.registration:
class: PCUserBundle\Form\RegistrationFormType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: pc_user_registration }
表格出现但没有字段真实姓名...
【问题讨论】:
标签: forms symfony fosuserbundle