2

I have a BaseBundle that I need to extend to override a small number of templates and eventually controller functions. I'm using annotations, so app/config/routing.yml references "@BaseBundle/Controller/".

When I create CustomBundle that extends BaseBundle routing.yml just picks up CustomBundle's empty Controller folder. Is there a way make this behave correctly other than creating classes to override very single controller in BaseBundle even when I don't want to change anything?

UPDATE: Extending BaseBundle also has the additional problem of breaking all of it's @Template() annotations. If I do create an empty controller that extends BaseBundle's controllers it complains about not being able to find the non-existent CustomBundle:Default:index.html.twig template.

j0k
  • 22,600
  • 28
  • 79
  • 90
Asa Ayers
  • 4,854
  • 6
  • 40
  • 57

1 Answers1

1

I had the same issue and found that by not modifying the main bundle file (AcmeCustomBundle.php) as the documentation suggest fixed the problem.

i.e. Don't use:

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

in my CustomBundle Default Controller I have:

use Acme\BaseBundle\Controller\DefaultController as BaseDefaultController;
class DefaultController extends BaseDefaultController

In my BaseBundle controllers I had to define all my @Template() annotations explicitly as @Template("AcmeBaseBundle:Default:index.html.twig") etc and then when overriding specific controller actions I either use @Template() in the CustomBundle controller actions to use the CustomeBundle template, or explicitly state the BaseBundle template again if I dont want to override the template. For any action you dont want to override just leave it out of the CustomBundle controller and the BaseBundle controller will be used.

  • actually http://stackoverflow.com/questions/9373433/symfony2-bundle-inheritance-losing-parent-bundles-routes seems to answer the question better. Using the absolute path to the BaseBundle controller folder seemed to work while using the getParent function as well, and then you can override templates easier without having to override the controller action as well. I still had to specify the templates explicitly in the base bundle controllers though. – Russell Thompson Jun 05 '12 at 11:38