![](/img/trans.png)
[英]Could not load type “acme_user_registration” FOSUserBundle
[英]FOSUserBundle - Overriding forms: could not load type “user_registration”
我在Me\\MyBundle\\Form\\Type\\UserFormRegistrationType
创建了我自己的表单类型:
namespace Me\MyBundle\Form\Type;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UserFormRegistrationType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
// all my unique fields
}
public function getName()
{
return 'user_registration';
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('data_class' => 'Me\MyBundle\Entity\User'));
}
}
我的 services.yml 中有以下内容:
services:
me_my.registration.form.type:
class: Me\MyBundle\Form\Type\UserFormRegistrationType
arguments: [%fos_user.model.user.class%]
tags:
- { name: form.type, alias: user_registration }
并将以下内容添加到我的 config.yml 中:
# other config stuff
fos_user:
# database stuff, general config
registration:
form:
type: user_registration
然而,当我尝试访问我的注册表/页面时,我得到:
无法加载类型“user_registration”
对我显然缺少什么的任何提示? 这不是防火墙问题。 我有一个,但调整我的 security.yml 修复了它。 这是一个纯粹的未发现错误。 非常烦人,因为我相信我按照文档进行了操作。
你不应该再使用别名
在您的配置文件中:
之前: registration: form: type: user_registration
新: registration: form: type: 'CoreBundle\\Form\\Type\\RegistrationFormType'
在你的 src/CoreBundle/Form/Type/RegistrationFormType.php: getParent() 函数应该是:
public function getParent()
{
return "FOS\UserBundle\Form\Type\RegistrationFormType";
}
不要忘记文件顶部的use FOS\\UserBundle\\Form\\Type\\RegistrationFormType;
: use FOS\\UserBundle\\Form\\Type\\RegistrationFormType;
嗨,这里是解释: https : //stackoverflow.com/a/53048060/7888453
官方:https ://github.com/symfony/symfony/blob/3.4/UPGRADE-3.0.md#form
看看这个家伙的问题,然后他为自己的问题提供的解决方案。 我离开了他的代码并修改了它以匹配我文件中的名称并且它起作用了!
文档拒绝提及/提醒该服务需要在 config.yml 中注册。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.