2012-06-09 78 views
4

我试图覆盖FOSUserBundle登记表,但我得到这个错误: 我按照这个教程的官方文档中: Link压倒一切的注册FOSUserBundle Symfony2的

Could not load type "uae_user_registration" 

我的文件是: services.yml

# src/Uae/UserBundle/Resources/config/services.yml 
services: 
    uae_user.registration.form.type: 
     class: Uae\UserBundle\Form\Type\RegistrationFormType 
     arguments: [%fos_user.model.user.class%] 
     tags: 
     - { name: form.type, alias: uae_user_registration } 

config.yml:

应用/配置/ config.yml

fos_user: 
    db_driver:  orm       
    firewall_name: main      
    user_class: Uae\UserBundle\Entity\User 
    registration: 
      form: 
       type: uae_user_registration 

RegistrationFormType:

<?php 
#src/Uae/UserBundle/Form/Type/RegistrationType.php 

namespace Uae\UserBundle\Form\Type; 

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

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

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

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

回答

9

我解决我的问题: 我刚刚导入,我在配置文件中 应用程序创建新的服务\ CONFIG \ config.yml

imports: 
    - { resource: @UaeUserBundle/Resources/config/services.yml } 
+1

为我工作。谢谢。 – iizno

+1

如果您回答了您自己的问题,请通过单击答案中的复选标记来标记答案。 –

6

您收到错误的原因是因为您没有针对您的特定包的DependencyInjection。该程序不知道在哪里查找您的services.yml文件。

你需要一个UaeUserExtension.php和Configuration.php在你的用户包下的DependencyInjection文件夹中。

这个简单的解决方案是通过app/console generate:bundle生成捆绑包。这样,它会自动为您创建您的DependencyInjection。

手动解决方案是在您的Uae/UserBundle中创建一个DependencyInjection文件夹。里面DependencyInjection,创建一个名为的configuration.php文件,并将以下内容:

<?php 

namespace Uae\UserBundle\DependencyInjection; 

use Symfony\Component\Config\Definition\Builder\TreeBuilder; 
use Symfony\Component\Config\Definition\ConfigurationInterface; 

class Configuration implements ConfigurationInterface 
{ 
    /** 
    * {@inheritDoc} 
    */ 
    public function getConfigTreeBuilder() 
    { 
     $treeBuilder = new TreeBuilder(); 
     $rootNode = $treeBuilder->root('uae_user'); 

     return $treeBuilder; 
    } 
} 

并创建一个名为UaeUserExtension.php同一目录内的文件,里面放上这些内容:

<?php 

namespace Uae\UserBundle\DependencyInjection; 

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

class EnergyUserExtension 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'); 
    } 
}