![](/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.