如果你在 Symfony 中有 2 条相同的路由怎么办?
What if you have 2 identical routes in Symfony?
我正在尝试了解 Symfony 5 路由的工作原理。
如果在我的项目中有 2 个具有相同路由名称的不同控制器会怎样?
例如,在Controller1.php中:
/**
* @Route("/publisher/notification_update/")
*/
在Controller2.php中:
/**
* @Route("/publisher/notification_update/")
*/
然后从树枝内部的某个地方,我有一个调用这条路线的表格如下:
<form name="notification" id="notification{{message.notification_id}}"
action="/publisher/notification_update/" style="display:none"
method="post">
<input hidden class="hiddenNotificationsForUser" type="text" id="{{message.notification_id}}"
value="{{message.message}}" onclick="this.form.submit();" />
</form>
在这种情况下会发生什么?会不会出错,还是会去到它按字母顺序找到的第一条路线?
在 DigitalOcean 的 LEMP 服务器上使用 Symfony 5 重现此场景后,我发现没有错误或警告消息。
Symfony 选择了 Controller1.php 中指定的路由:
/**
* @Route("/publisher/notification_update/")
*/
然而,这是一件坏事,因为将我描述的情况与大型代码库结合起来可能会导致很难识别错误。
即使内容正确,您也可能永远无法到达所需的路线。
我正在尝试了解 Symfony 5 路由的工作原理。
如果在我的项目中有 2 个具有相同路由名称的不同控制器会怎样?
例如,在Controller1.php中:
/**
* @Route("/publisher/notification_update/")
*/
在Controller2.php中:
/**
* @Route("/publisher/notification_update/")
*/
然后从树枝内部的某个地方,我有一个调用这条路线的表格如下:
<form name="notification" id="notification{{message.notification_id}}"
action="/publisher/notification_update/" style="display:none"
method="post">
<input hidden class="hiddenNotificationsForUser" type="text" id="{{message.notification_id}}"
value="{{message.message}}" onclick="this.form.submit();" />
</form>
在这种情况下会发生什么?会不会出错,还是会去到它按字母顺序找到的第一条路线?
在 DigitalOcean 的 LEMP 服务器上使用 Symfony 5 重现此场景后,我发现没有错误或警告消息。
Symfony 选择了 Controller1.php 中指定的路由:
/**
* @Route("/publisher/notification_update/")
*/
然而,这是一件坏事,因为将我描述的情况与大型代码库结合起来可能会导致很难识别错误。 即使内容正确,您也可能永远无法到达所需的路线。