本文介绍了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.phpsrc/Application/FOS/UserBundle/ApplicationFOSUserBundle.php

Now I want to overridee FOSUserBundle ChangePasswordController. So I made:src/Application/FOS/UserBundle/Controller/ChangePasswordController.phpsrc/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.

推荐答案

不可能通过捆绑继承来使两个捆绑扩展同一个捆绑.原因很简单...如果两个扩展包中都有相同的文件,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';
}

这篇关于SonataUserBundle + FOSUserBundle-覆盖控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:54