使用此article我试图覆盖RegisterFormType.php,但看不到结果,但是表格中的Symfony Profiler会被app_user_registration覆盖fos_user_registration。
首先,我有AppKernel.php:
new FOS\UserBundle\FOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
services.yml
app.form.registration:
class: Application\Sonata\UserBundle\Form\RegistrationFormType
tags:
- { name: form.type, alias: app_user_registration }
config.yml:
fos_user:
db_driver: orm # can be orm or odm
firewall_name: main
user_class: Application\Sonata\UserBundle\Entity\User
use_listener: true
group:
group_class: Application\Sonata\UserBundle\Entity\Group
group_manager: sonata.user.orm.group_manager # If you're using doctrine orm (use sonata.user.mongodb.group_manager for mongodb)
service:
user_manager: sonata.user.orm.user_manager # If you're using doctrine orm (use sonata.user.mongodb.user_manager for mongodb)
registration:
form:
type: app_user_registration
#validation_groups: [AppRegistration]
profile:
form:
name: app_user_profile
的src /应用/奏/ UserBundle /形式/ RegistrationForm.php:
namespace Application\Sonata\UserBundle\Form;
use ...
class RegistrationFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('fullName')
;
}
public function getParent() {
return "fos_user_registration";
}
public function getName() {
return 'app_user_registration';
}
}
的src /应用/奏/ UserBundle /实体/ user.php的:
namespace Application\Sonata\UserBundle\Entity;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
class User extends BaseUser
{
/**
* @var int $id
*/
protected $id;
/**
* @var string
*/
protected $fullName;
/**
* @return string
*/
public function getFullName() {
return $this->fullName;
}
/**
* @param string $fullName
*/
public function setFullName($fullName) {
$this->fullName = $fullName;
}
/**
* Get id
*
* @return int $id
*/
public function getId() { return $this->id;}
}
正如其他方式(我认为不正确)试图覆盖我的自定义目录中的RegistrationController.php,更改了$form = $this->container->get('app.form.registration')
(我的表单的别名),但我收到错误Attempted to call an undefined method named "createView" of class "Application\Sonata\UserBundle\Form\RegistrationFormType
。在此之后,我将此类的父扩展类从ContentAware更改为Controller,并且可以看到表单和新字段,但是在提交接收到未知错误之后,即使在Profiler中也没有写过它的名称。
Symfony 2.8.18,FOSUserBundle 1.3.7。谢谢你的时间。
答案 0 :(得分:0)
您是否在config.yml中更新了FOSUserBundle的配置?
fos_user:
# ...
registration:
form:
name: app_user_registration