Add data to return of all actions in a Symfony controller

后端 未结 2 1619
一向
一向 2021-01-24 09:24

I have a controller in a Symfony 2.1 application, let\'s just call it FooController in the BarBundle. This controller has a lot of actions fooAct

2条回答
  •  無奈伤痛
    2021-01-24 09:42

    One of options

    public function commonAction($type) {
         // ...
         return $this->render('BarBundle:Foo:'.$type.'.html.twig', array('data' => $this->getTheDataThatIsNeededInEveryAction()));
    }
    

    where $type would be bar, foo or baz

提交回复
热议问题