SonataUserBundle + FOSUserBundle - 覆盖控制器

0 php overriding symfony fosuserbundle sonata-user-bundle

我正在使用带有FOSUserBundle的SonataUserBundle.在AppKernel.php中它看起来像这样:

 new FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
Run Code Online (Sandbox Code Playgroud)

SonataUserBundle的一些控制器已被覆盖.

现在我想要覆盖FOSUserBundle ChangePasswordController.所以我做了:src/Application/FOS/UserBundle/Controller/ChangePasswordController.php src/Application/FOS/UserBundle/ApplicationFOSUserBundle.php

<?php
namespace Application\FOS\UserBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ApplicationFOSUserBundle extends Bundle
{
    /**
    * {@inheritdoc}
    */
    public function getParent()
    {
        return 'FOSUserBundle';
    }
}
Run Code Online (Sandbox Code Playgroud)

以及修改过的AppKernel.php

 new FOS\UserBundle\FOSUserBundle(),
 new Application\FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
Run Code Online (Sandbox Code Playgroud)

问题是......它无法正常工作.

致命错误:带有消息'Bundle"FOSUserBundle"的未捕获异常'LogicException'由两个捆绑包"SonataUserBundle"和"ApplicationFOSUserBundle"直接扩展.在第2364行的/home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache中(!)LogicException:Bundle"FOSUserBundle"由两个包"SonataUserBundle"和"ApplicationFOSUserBundle"直接扩展.在2364行的/home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache中

Nic*_*ich 9

不可能有两个bundle使用bundle继承扩展同一个bundle.原因很简单......如果两个扩展包中都有相同的文件,symfony将如何知道要使用哪个文件...因此,bundle继承只能是线性的.

这意味着在你的情况下FOSUserBundle- > SonataUserBundle- > YourBundle.

您的捆绑包必须扩展,SonataUserBundle因为SonataUserBundle已经扩展了FOSUserBundle.

public function getParent()
{
    return 'SonataUserBundle';
}
Run Code Online (Sandbox Code Playgroud)