SonataUserBundle + FOSUserBundle - overriding controllers

僤鯓⒐⒋嵵緔 提交于 2019-12-24 23:22:52

问题


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(),

Some controllers from SonataUserBundle are already overriden.

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';
    }
}

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.

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


回答1:


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.

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

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

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


来源:https://stackoverflow.com/questions/18571884/sonatauserbundle-fosuserbundle-overriding-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!