【发布时间】:2014-03-06 03:34:43
【问题描述】:
我想更改 @Template 注释的默认行为,它会自动呈现名为控制器操作的模板。
所以在ArticleController.php
/**
* @Route("/new", name="article_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
// ...
return array();
}
将呈现Article/new.html.twig。
我想将其更改为引用调用该操作的路由的名称,这样您就可以为一个操作有多个路由,每个路由都呈现不同的模板。
这是我目前的做法(没有@Template):
/**
* @Route("/new", name="article_new")
* @Route("/new_ajax", name="article_new_ajax")
* @Method("GET")
*/
public function newAction()
{
// ...
$request = $this->getRequest();
$route = $request->attributes->get('_route');
$template = 'AcmeDemoBundle:' . $route . '.html.twig';
return $this->render($template, array(
// ...
));
}
我现在想知道是否有办法改变@Template 的行为来做到这一点。有没有办法自定义注释,或者只是一些让它更自动化的方法?
有什么想法吗?
【问题讨论】:
标签: symfony annotations routes templating