【问题标题】:Could not load type "XYZ" error when overriding FOSUserBundle form types覆盖 FOSUserBundle 表单类型时无法加载类型“XYZ”错误
【发布时间】:2011-10-26 13:48:08
【问题描述】:

我试图覆盖 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

【问题讨论】:

  • 在服务定义中用%fos_user.model.user.form_data_class%这个参数代替%fos_user.model.user.class%怎么样?

标签: php symfony symfony-plugins


【解决方案1】:

原来我的 services.yml 文件不是通过依赖注入加载的。在四处挖掘之后,我意识到这个包的 extension.php 文件命名不正确。早些时候,我重命名了捆绑包并在重命名 DependencyInjection 文件夹中的 extension.php 文件时打错了字。更正拼写错误后,一切都恢复正常了。

【讨论】:

  • 完美,我也错过了我的扩展文件。
【解决方案2】:

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

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

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

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

【讨论】:

  • 我有,但似乎没有帮助。我什至尝试过从 Symfony\Component\Form\AbstractType; 扩展。同时添加 FOS 的 RegistrationFormType 使用的构造函数和 getDefaultOptions 逻辑。这似乎也没有解决它。
  • 看起来很奇怪。如果这发生在我身上,我会尝试“按原样”遵循 FOSUserBundle 的文档,然后对所需的配置进行一些小改动......
  • 是的,这很奇怪...我将尝试回滚我的代码并再次实现具有我的 FOS 自定义的捆绑包。
猜你喜欢
  • 1970-01-01
  • 2017-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-10
  • 2020-09-05
  • 1970-01-01
相关资源
最近更新 更多