无法加载类型“XYZ”覆盖 FOSUserBundle 表单类型时出错

发布于 2024-12-12 04:32:59 字数 1834 浏览 0 评论 0原文

我正在尝试覆盖 Symfony2 FOSUserBundle 中的 RegistrationFormType。我正在遵循文档并相信我已经涵盖了所有内容。我创建了一个包来包含对 FOSUserBundle 的覆盖,以下代码来自该包以及应用程序配置。

有没有人在覆盖 FOSUserBundle 时经历过这种情况,或者在我的代码中看到任何有助于解释为什么我不断收到此错误的内容。 我在 symfony v2.0.4

RegistrationFormType.php

<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Thrive\SaasBundle\Form\Type;

use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('firstname', null, array('error_bubbling' => true))
            ->add('lastname', null, array('error_bubbling' => true))
            ->add('company', null, array('error_bubbling' => true))
            ->add('email', 'email', array('error_bubbling' => true))
            ->add('username', null, array('error_bubbling' => true))
            ->add('plainPassword', 'repeated', array('type' => 'password', 'error_bubbling' => true))
            ;
    }

    public function getName()
    {
        return 'thrive_user_registration';
    }

}

Services.yml

services:
  thrive_saas_registration.form.type:
    class: Thrive\SaasBundle\Form\Type\RegistrationFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: thrive_user_registration}

应用程序的配置文件

fos_user:
     ...
    registration: 
      form:
        type: thrive_user_registration

I am attempting to override the RegistrationFormType in the Symfony2 FOSUserBundle. I am following the documentation and believe i've covered everything. I've created a bundle to contain my overrides to the FOSUserBundle and the following code is from this bundle as well as the application config.

Has anyone experienced this when overriding FOSUserBundle, or see anything in my code that would help explain why I keep getting this error.
I'm on symfony v2.0.4

RegistrationFormType.php

<?php

/*
 * This file is part of the FOSUserBundle package.
 *
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Thrive\SaasBundle\Form\Type;

use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;

class RegistrationFormType extends BaseType
{

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('firstname', null, array('error_bubbling' => true))
            ->add('lastname', null, array('error_bubbling' => true))
            ->add('company', null, array('error_bubbling' => true))
            ->add('email', 'email', array('error_bubbling' => true))
            ->add('username', null, array('error_bubbling' => true))
            ->add('plainPassword', 'repeated', array('type' => 'password', 'error_bubbling' => true))
            ;
    }

    public function getName()
    {
        return 'thrive_user_registration';
    }

}

Services.yml

services:
  thrive_saas_registration.form.type:
    class: Thrive\SaasBundle\Form\Type\RegistrationFormType
    arguments: [%fos_user.model.user.class%]
    tags:
        - { name: form.type, alias: thrive_user_registration}

Application's Config File

fos_user:
     ...
    registration: 
      form:
        type: thrive_user_registration

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2024-12-19 04:32:59

事实证明我的 services.yml 文件没有通过依赖项注入加载。经过一番研究后,我意识到这个包的 extension.php 文件命名不正确。早些时候,我重命名了该包,并在重命名 DependencyInjection 文件夹内的 extension.php 文件时犯了一个拼写错误。纠正拼写错误后,一切又恢复正常了。

Turns out my services.yml file wasn't being loaded via dependency injection. After digging around i realized my extension.php file for this bundle was named incorrectly. Early on I had renamed the bundle and made a typo when renaming the extension.php file inside the DependencyInjection folder. After correcting the mispelling everything works again.

凉城已无爱 2024-12-19 04:32:59

您是否尝试过添加一个新字段并看看它是否有效?

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('name');
}

如果您从那里进行测试,还请记住清除您的产品缓存......

Did you tried to just add one new field and look if it works?

public function buildForm(FormBuilder $builder, array $options)
{
    parent::buildForm($builder, $options);

    // add your custom field
    $builder->add('name');
}

Also remember to clear your prod cache if you're testing from there...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文