SonataUserBundle + FOSUserBundle-覆盖控制器

SonataUserBundle + FOSUserBundle-覆盖控制器

问题描述:

我正在将SonataUserBundle与FOSUserBundle一起使用. 在AppKernel.php中,它看起来像这样:

I'm using SonataUserBundle with FOSUserBundle. in AppKernel.php it looks like this:

 new FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),

SonataUserBundle中的某些控制器已被覆盖.

Some controllers from SonataUserBundle are already overriden.

现在,我想覆盖FOSUserBundle ChangePasswordController.所以我做了: src/应用程序/FOS/UserBundle/Controller/ChangePasswordController.php src/Application/FOS/UserBundle/ApplicationFOSUserBundle.php

Now I want to overridee FOSUserBundle ChangePasswordController. So I made: 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';
    }
}

以及修改后的AppKernel.php

as well as modified AppKernel.php

 new FOS\UserBundle\FOSUserBundle(),
 new Application\FOS\UserBundle\FOSUserBundle(),
 new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
 new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),

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

The problem is... it's not working correctly.

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

Fatal error: Uncaught exception 'LogicException' with message 'Bundle "FOSUserBundle" is directly extended by two bundles "SonataUserBundle" and "ApplicationFOSUserBundle".' in /home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache on line 2364 ( ! ) LogicException: Bundle "FOSUserBundle" is directly extended by two bundles "SonataUserBundle" and "ApplicationFOSUserBundle". in /home/piotr.gawlowski/dev_dash_devel/dev-dash/app/bootstrap.php.cache on line 2364

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

It is not possible to have two bundles extend the same bundle with bundle inheritance. The reason is simple ... how would symfony know which file to use if there was the same file in both extending bundles... Therefore bundle inheritance can only be linear.

在您的情况下,这表示FOSUserBundle-> SonataUserBundle-> YourBundle.

This means in your case FOSUserBundle -> SonataUserBundle -> YourBundle.

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

Your bundle has to extend SonataUserBundle because SonataUserBundle already extends FOSUserBundle.

public function getParent()
{
    return 'SonataUserBundle';
}