0

最近我从 Symfony 2.4 转移到 Symfony 2.7

所以我在关注新文档。现在说我action functions在同一个控制器中有 2 个。

public function indexAction() {}

public function changeRateAction()

以前我会使用routing.yml

change_interest_rate_label:
    path: /change_interest_rate
    defaults: { _controller: appBundle:appInterestRateChange:index }

change_interest_rate_action_label:
    path: /change_interest_rate_and_archived_action
    defaults: { _controller: appBundle:appInterestRateChange:changeRate }

现在在 2.7 文档中,鼓励使用注释。内部controller文件

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

这将触发控制器文件中包含的操作方法。但是如何为同一控制器文件中包含的不同 url 的 2 种方法编写注释?

这意味着我在同一个控制器文件中有indexAction& 。changeRateAction我想/home用 index 函数和/changechangeRate 函数路由 url。如何使用注释来做到这一点?我知道如何使用routing.yml

4

1 回答 1

3

您实际上是在方法上使用注释路由,而不是在控制器上。

您只需在每个方法之前指定路线。在你的情况下,它会是这样的:

/**
 * @Route("/home", name="homepage")
 */
public function indexAction() {
    ...
}

/**
 * @Route("/change", name="changerate")
 */
public function changeRateAction() {
    ...
}

请务必在文档中阅读有关路由的更多信息:http: //symfony.com/doc/current/book/routing.html

于 2015-11-11T11:56:36.440 回答