![](/img/trans.png)
[英]Could not load type “acme_user_registration” FOSUserBundle
[英]FOSUserBundle overwrite registration but Could not load type error
我嘗試使用FOSUserBundle,我按照文檔中的說明覆蓋了Bundle,但是當我嘗試在/ login工作時訪問/ register時遇到此錯誤(我沒有覆蓋它):
Could not load type "app_user_registration"
500 Internal Server Error - InvalidArgumentException
配置
Symfony版本: 3.1.7
FOSUserBundle版本: dev-master
我的文件
應用程序/配置/ services.yml:
services:
app.form.registration:
class: CoreBundle\Form\Type\RegistrationFormType
tags:
- { name: form.type, alias: app_user_registration }
應用程序/配置/ config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: CoreBundle\Entity\User
registration:
form:
type: app_user_registration
SRC / CoreBundle /表/類型/ RegistrationFormType.php
<?php
// src/CoreBundle/Form/Type/RegistrationFormType.php
namespace CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
}
public function getParent()
{
return 'fos_user_registration';
}
public function getName()
{
return 'app_user_registration';
}
}
?>
SRC / viwa / UserBundle /控制器/ RegistrationController.php:
<?php
// src/viwa/UserBundle/Controller/RegistrationController.php
namespace viwa\UserBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as BaseController;
class RegistrationController extends BaseController
{
// Don't need to change this right now.
}
?>
SRC / viwa / UserBundle / viwaUserBundle.php:
<?php
// src/viwa/UserBundle/viwaUserBundle.php
namespace viwa\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class viwaUserBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
如果您需要其他任何幫助,我可以編輯我的帖子。
希望任何人都能幫助我。
您的config.yml文件應為:
fos_user:
db_driver: orm
firewall_name: main
user_class: CoreBundle\Entity\User
registration:
form:
type: CoreBundle\Form\Type\RegistrationFormType
在src/CoreBundle/Form/Type/RegistrationFormType.php
, getParent()
函數應為:
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
您可能已經閱讀了默認打開的“ 1.3.x / current”文檔。 如果切換到“ 2.0 / master”,則將使用正確版本的文檔。
我知道這是一個古老的問題,但是當我發現它正在尋找相同的問題時,我會像接受的答案一樣共享我的解決方案,但更符合建議的/官方的語法:)我現在已升級到symfony 3.4和FosUserBundle 2.1您需要按照升級版2.x到3.0中的說明返回FQCN
從FormTypeInterface :: getParent()返回類型實例不再受支持。 而是返回父類型類的全限定類名。
之前:
class MyType
{
public function getParent()
{
return new ParentType();
}
}
后:
class MyType
{
public function getParent()
{
return ParentType::class;
}
}
在這種情況下:
public function getParent()
{
return RegistrationFormType::class;
}
不要忘記文件頂部的用法:
use FOS\UserBundle\Form\Type\RegistrationFormType;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.