简体   繁体   English

FOSUserBundle - 覆盖表单:无法加载类型“user_registration”

[英]FOSUserBundle - Overriding forms: could not load type “user_registration”

I created my own form type at Me\\MyBundle\\Form\\Type\\UserFormRegistrationType :我在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'));
    }
}

I have the following in my services.yml:我的 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 }

And the following added to my config.yml:并将以下内容添加到我的 config.yml 中:

# other config stuff

fos_user:
    # database stuff, general config

    registration:
        form:
            type: user_registration

Yet, when I try to access my registration form/page, I get:然而,当我尝试访问我的注册表/页面时,我得到:

Could not load type "user_registration"无法加载类型“user_registration”

Any hint to what I'm obviously missing?对我显然缺少什么的任何提示? It's not a firewall issue.这不是防火墙问题。 I had one, but tweaking my security.yml fixed it.我有一个,但调整我的 security.yml 修复了它。 This is a pure not found error.这是一个纯粹的未发现错误。 Very annoying, as I believe I followed the docs to the letter.非常烦人,因为我相信我按照文档进行了操作。

You should not use aliases anymore你不应该再使用别名

In your config file :在您的配置文件中:

Before : registration: form: type: user_registration之前: registration: form: type: user_registration

New : registration: form: type: 'CoreBundle\\Form\\Type\\RegistrationFormType'新: 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";
}

Don't forget the use on the top of the file : use FOS\\UserBundle\\Form\\Type\\RegistrationFormType;不要忘记文件顶部的use FOS\\UserBundle\\Form\\Type\\RegistrationFormType;use FOS\\UserBundle\\Form\\Type\\RegistrationFormType;

Hi here is the explanation : https://stackoverflow.com/a/53048060/7888453嗨,这里是解释: https : //stackoverflow.com/a/53048060/7888453

Official :https://github.com/symfony/symfony/blob/3.4/UPGRADE-3.0.md#form官方:https ://github.com/symfony/symfony/blob/3.4/UPGRADE-3.0.md#form

Take a look at this guys problem and then the solution that he provides to his own question.看看这个家伙的问题,然后他为自己的问题提供的解决方案。 I went off of his code and modified it to match the names within my files and it worked!我离开了他的代码并修改了它以匹配我文件中的名称并且它起作用了!

How to override register form FosUserBundle? 如何覆盖注册表单 FosUserBundle?

文档拒绝提及/提醒该服务需要在 config.yml 中注册。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM