我按照这些说明向用户实体添加了一个字段: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 }
表单出现但没有字段真实姓名......
答案 0 :(得分:0)
在app配置文件中,试试这个:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
registration:
form:
type: AppBundle\Form\RegistrationType
confirmation:
enabled: true