[英]Symfony 2 route with no custom controller code
I have my routes defined using annotations in my SF2 application, however there are a handful of pages which although they have a distinct route and Twig template they require no controller code whatsoever which leads to empty methods such as this: 我在SF2应用程序中使用注释定义了路由,但是有少数页面尽管它们具有独特的路由和Twig模板,但它们不需要任何控制器代码,而这会导致诸如以下的空方法:
/**
* @Route(
* "/courselimit",
* name = "course_limit"
* )
* @Template("CRMPiccoBundle:Course:Limit.html.twig")
*
* @param Request $request
*
* @throws \Exception
*/
public function courseLimitAction(Request $request)
{
}
This, to me, seems pointless and messy. 在我看来,这似乎毫无意义且混乱。 Is there a way to avoid this in SF2 without converting all my routes to be managed in YAML files? 有没有一种方法可以在SF2中避免这种情况,而无需将所有路由都转换为在YAML文件中进行管理?
You would edit app/config/routing.yml
like so: 您可以像这样编辑app/config/routing.yml
:
# app/config/routing.yml
course_limit:
path: /courselimit
defaults:
_controller: FrameworkBundle:Template:template
template: path/Limit.html.twig
Examples are shown in the Render Template without a custom Controller: http://symfony.com/doc/2.7/templating/render_without_controller.html 在没有自定义控制器的“渲染模板”中显示了示例: http : //symfony.com/doc/2.7/templating/render_without_controller.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.