无法在symfony2中加载类型

时间:2014-09-02 17:14:28

标签: symfony fosuserbundle

我在使用FosUserBundle的Symfony2中遇到问题。 我尝试重载表单“ChangePasswordFormType”以删除名为“old password”的字段

我收到错误:

Could not load type "wsa_user_change_password"

这是我创建的表单/UserBundle/Form/Type/ChangePasswordFormType.php:

<?php

namespace Wsa\UserBundle\Form\Type;

use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\ChangePasswordFormType as BaseType;

class ChangePasswordFormType extends BaseType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        parent::buildForm($builder, $options);

        $builder->remove('current_password', 'password');
    }

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

我的UserBundle / Resources / config / services.yml

services:
    wsa_user.change_password.form.type:
            class: Wsa\UserBundle\Form\Type\ChangePasswordFormType
            arguments: [%fos_user.model.user.class%]
            tags:
                - { name: form.type, alias: wsa_user_change_password }

我的app / config / config.yml

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: Wsa\UserBundle\Entity\User
    change_password:
        form:
            type: wsa_user_change_password
            name: wsa_user_change_password

和我的控制员:

public function modifierCompteAction($id)
    {

        $userManager = $this->get('fos_user.user_manager');
        $user = $userManager->findUserBy(array('id' => $id));

        $userModifyType = new UserEditType($user);
        $form = $this->createForm($userModifyType, $user);

        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->container->get('fos_user.change_password.form.factory');
        $formChangePassword = $formFactory->createForm();
        $formChangePassword->setData($user);

        // Récupération de la requête
        $request = $this->get('request');

        // On vérifie qu'elle est en type POST
        if ($request->getMethod() === 'POST')
[...]

我认为我的文件services.yml是dos not load ..因为如果我尝试在我的控制器中直接加载我的服务:

$formFactory = $this->container->get('wsa_user.change_password.form.type');
$formChangePassword = $formFactory->createForm();
$formChangePassword->setData($user);

现在我有这个错误:

You have requested a non-existent service "wsa_user.change_password.form.type".

我的UserBundle \DepêndencyInjection\ WsaUserExtension.php

<?php

namespace Wsa\UserBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
 * This is the class that loads and manages your bundle configuration
 *
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
 */
class WsaUserExtension extends Extension
{
    /**
     * {@inheritDoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {

        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}

0 个答案:

没有答案