【问题标题】:What is the point of the name method in the symfony2 annotation?symfony2 注释中的 name 方法有什么意义?
【发布时间】:2015-06-09 00:12:30
【问题描述】:
/**
*@Route ("/hello/{name}", name="_demo_hello")
*
**/

我在这个 youtube 教程中看到了这个方法 Go to 7:36 我想知道“名称”方法的意义是什么?可以补一下name方法吗?

提前谢谢你。

【问题讨论】:

    标签: symfony model-view-controller annotations controllers


    【解决方案1】:

    如果您想自定义路由的名称,则使用注释定义路由时的name 选项非常有用。默认情况下,如果没有指定name,Symfony 将根据控制器的动作名称生成一个名称,如下所示: indexAction in the WebController of the AppBundle => app_web_index

    但是你可以使用 name 选项来改变它:

    @Route ("/", name="homepage")

    然后您可以使用此名称在您的控制器或模板中引用此路由:

    {{ path('homepage') }}

    【讨论】:

      猜你喜欢
      • 2011-01-07
      • 2018-06-10
      • 1970-01-01
      • 2013-11-12
      • 2023-03-06
      • 2018-09-23
      • 2015-06-13
      • 2014-05-02
      • 1970-01-01
      相关资源
      最近更新 更多