覆盖FOSUserBundle控制器

Jim*_*oot 2 symfony fosuserbundle symfony-2.3

所以我读了很多关于模板的重写,以及Symfony中的包的重写.

我正在使用新的Symfony 2.3,我没有在较低版本的Symfony中尝试过这个.

我按照教程中关于覆盖Symfony中的bundle:http: //symfony.com/doc/2.3/cookbook/bundles/inheritance.html

我按照关于覆盖FOSUserBundle控制器的教程,这是真的一样:https: //github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md

我有一个名为Acme/WebBundle的软件包.

现在我做了以下事情:

  • 创建了一个名为Acme/UserBundle的新包.
  • 在此捆绑包中创建了文件AcmeUserBundle.php.

    <?php
    
    namespace Acme\UserBundle;
    
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    
    class AcmeUserBundle extends Bundle
    {
        public function getParent()
        {
            return 'FOSUserBundle';
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 创建了以下文件结构:

    -src
        -Acme
            -UserBundle
                -Controller
                    RegistrationController.php
                -Entity
                    User.php
                -Resources
                    -translations
                    -views
                AcmeUserBundle.php
    
    Run Code Online (Sandbox Code Playgroud)
  • 在RegistrationController.php中,我将命名空间设置为:

    namespace Acme\UserBundle\Controller;
    
    Run Code Online (Sandbox Code Playgroud)
  • 将FOSUserBundle的注册控制器的内容复制到我的.

  • 添加到registerAction()的开头

    die("message");
    
    Run Code Online (Sandbox Code Playgroud)

现在,当我去注册表格,默认/注册路线,我没有死,一切正常.它没有看到我的小孩作为一个孩子,没有被覆盖,我一直试图让它工作多年,因此我的问题在这里.

我做错什么了吗?

red*_*rdo 6

请记住,您需要在app/AppKernel.php中将任何新包添加到AppKernel :: registerBundles(),如下所示:

    $bundles = array(
        ...
        new Acme\UserBundle()
    );
Run Code Online (Sandbox Code Playgroud)