Symfony路由未找到但存在于调试器路由结果中

时间:2017-04-17 18:47:24

标签: php symfony

我生成了一个包但是在尝试访问网址http://localhost/app_dev.php/event时收到错误:

No route found for "GET /event"

然后我使用debug:router调试路由器,路由器似乎很好:

event_homepage             ANY        ANY      ANY    

/hello/{firstName}/{count}         
event_index                GET        ANY      ANY    /event/                            
event_show                 GET        ANY      ANY    /event/{id}/show                   
event_new                  GET|POST   ANY      ANY    /event/new                         
event_edit                 GET|POST   ANY      ANY    /event/{id}/edit                   
event_delete               DELETE     ANY      ANY    /event/{id}/delete        

我自动创建了包后发生了这个错误:

[ERROR] The bundle's "Resources/config/routing.yml" file cannot be imp
orted
from "app/config/routing.yml" because the "EventBundle" bundle is
already imported. Make sure you are not using two different
configuration/routing formats in the same bundle because it won't work

以下是所有路由结构文件:

/home/stefano/starwarsevents/app/config/routing.yml

event:
resource: "@EventBundle/Resources/config/routing.yml"
prefix:   /

/home/stefano/starwarsevents/src/EventBundle/Resources/config/routing.yml

event_homepage:
path:     /hello/{firstName}/{count}
defaults: { _controller: EventBundle:Default:index }

event_event:
resource: "@EventBundle/Resources/config/routing/event.yml"
prefix:   /event

/home/stefano/starwarsevents/src/EventBundle/Resources/config/routing/event.yml

event_index:
path:     /
defaults: { _controller: "EventBundle:Event:index" }
methods:  GET

event_show:
path:     /{id}/show
defaults: { _controller: "EventBundle:Event:show" }
methods:  GET

event_new:
path:     /new
defaults: { _controller: "EventBundle:Event:new" }
methods:  [GET, POST]

event_edit:
path:     /{id}/edit
defaults: { _controller: "EventBundle:Event:edit" }
methods:  [GET, POST]

event_delete:
path:     /{id}/delete
defaults: { _controller: "EventBundle:Event:delete" }
methods:  DELETE

1 个答案:

答案 0 :(得分:1)

计算和需要斜杠。为了解决这个问题,我将这个RedirectingController放在我的代码库中作为(几乎)最终路由,以便捕获并重定向到无斜线版本,如果它发生的话。

但与此同时,网址目前为/event/,而不是/event。您也可以将备用路径作为备用路线放到同一个地方。