[英]FOSUserBundle overwrite registration but Could not load type error
I tried to use the FOSUserBundle, I followed the instructions on the documentation for overwriting the Bundle, but I get this error when I try to access to /register while /login works (I didn't overwrite it): 我尝试使用FOSUserBundle,我按照文档中的说明覆盖了Bundle,但是当我尝试在/ login工作时访问/ register时遇到此错误(我没有覆盖它):
Could not load type "app_user_registration"
500 Internal Server Error - InvalidArgumentException
Configurations 配置
Symfony version: 3.1.7 Symfony版本: 3.1.7
FOSUserBundle version: dev-master FOSUserBundle版本: dev-master
My files 我的文件
app/config/services.yml: 应用程序/配置/ services.yml:
services:
app.form.registration:
class: CoreBundle\Form\Type\RegistrationFormType
tags:
- { name: form.type, alias: app_user_registration }
app/config/config.yml: 应用程序/配置/ config.yml:
fos_user:
db_driver: orm
firewall_name: main
user_class: CoreBundle\Entity\User
registration:
form:
type: app_user_registration
src/CoreBundle/Form/Type/RegistrationFormType.php 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/Controller/RegistrationController.php: 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: 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';
}
}
If you need anything other to help me I edit my post. 如果您需要其他任何帮助,我可以编辑我的帖子。
Hope anyone can help me out. 希望任何人都能帮助我。
Your config.yml file should be: 您的config.yml文件应为:
fos_user:
db_driver: orm
firewall_name: main
user_class: CoreBundle\Entity\User
registration:
form:
type: CoreBundle\Form\Type\RegistrationFormType
In your src/CoreBundle/Form/Type/RegistrationFormType.php
, getParent()
function should be: 在src/CoreBundle/Form/Type/RegistrationFormType.php
, getParent()
函数应为:
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
You probably read documentation for '1.3.x / current' which is open by default. 您可能已经阅读了默认打开的“ 1.3.x / current”文档。 If you switch to '2.0 / master' you will se the correct version of documentation. 如果切换到“ 2.0 / master”,则将使用正确版本的文档。
I know it's an old question but as I found it searching for the same problem, I share my solution, like the accepted answer, but more conform to the suggested/official syntax :) I have upgraded to symfony 3.4, and FosUserBundle 2.1, now you need to return the FQCN as explain in the UPGRADE 2.x to 3.0 我知道这是一个古老的问题,但是当我发现它正在寻找相同的问题时,我会像接受的答案一样共享我的解决方案,但更符合建议的/官方的语法:)我现在已升级到symfony 3.4和FosUserBundle 2.1您需要按照升级版2.x到3.0中的说明返回FQCN
Returning type instances from FormTypeInterface::getParent() is not supported anymore. 从FormTypeInterface :: getParent()返回类型实例不再受支持。 Return the fully-qualified class name of the parent type class instead. 而是返回父类型类的全限定类名。
Before: 之前:
class MyType
{
public function getParent()
{
return new ParentType();
}
}
After: 后:
class MyType
{
public function getParent()
{
return ParentType::class;
}
}
In this case: 在这种情况下:
public function getParent()
{
return RegistrationFormType::class;
}
Don't forget the use on the top of the file: 不要忘记文件顶部的用法:
use FOS\UserBundle\Form\Type\RegistrationFormType;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.