如何覆盖注册表FosUserBundle? [英] How to override register form FosUserBundle?
问题描述
我想覆盖某些FOSUserBundle表单(注册表单),所以我遵循了文档,但我无法理解为什么我总是收到相同的错误:
I want to override some of FOSUserBundle forms ( registration form ) So I followed the documentation and I cant understand why I keep getting the same error :
试图从名称空间加载类"RegistrationFormType" "OC \ UserBundle \ Form \ Type".您是否忘记了使用"声明 "FOS \ UserBundle \ Form \ Type \ RegistrationFormType"? 500内部服务器错误-ClassNotFoundException.
Attempted to load class "RegistrationFormType" from namespace "OC\UserBundle\Form\Type". Did you forget a "use" statement for "FOS\UserBundle\Form\Type\RegistrationFormType"? 500 Internal Server Error - ClassNotFoundException.
这些是我的文件:
RegistrationFormType.php:
RegistrationFormType.php:
<?php
namespace OC\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('telephone');
}
public function getName()
{
return 'oc_user_registration';
}
}
OCUserBundle的
Service.yml:
Service.yml of the OCUserBundle:
services:
oc_user_registration:
class: OC\UserBundle\Form\Type\RegistrationFormType
tags:
- {name: form.type, alias: oc_user_registration}
,当用户尝试在app/Ressources/config.yml中进行注册时,我将项目配置为使用我的表单类型:
and I configured the project to use my form type when the user tries to register in the app/Ressources/config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: OC\UserBundle\Entity\User
registration:
form:
type: oc_user_registration
请有人告诉我这是怎么回事吗?
Please can someone tell me what's wrong here?
推荐答案
解决了这个问题.错误是到FormType文件的路径的路径与名称空间不同.还是谢谢你.
Solved this. The error was that the path to the path to the FormType file wasn't the same as the namespace. Thank you anyway.
这篇关于如何覆盖注册表FosUserBundle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!