symfony2 启用查找可选参数的路由错误

symfony2 enable to find routing error for optional parameter

我想为我的路线添加一种格式,但这个错误总是出现:

No route found for "GET /ecomerce/0" (from "http://localhost/ecomerce/web/app_dev.php/ecomerce/")
404 Not Found - NotFoundHttpException
1 linked Exception: ResourceNotFoundException 

这是我试过的

//<li> <a href='{{path('ecomerce_first',{'id':17})-'.html'}}'> First </a> </li>  

ecomerce_first:
    path: /{id}/first.{_format }
    defaults: { _controller: "EcomerceBundle:Default:firstTest" , _format: html }
    requirements: _format: html
    id: \d+

在 EcomerceBundle 的 routing.yml 中

据我了解,您想要这样的 url?

/ecomerce/1/first.html

尝试下一个解决方案:

<li> <a href='{{ path('ecomerce_first',{'id':17, '_format': 'html'})'}}'> First </a> </li>

PS:我注意到这里您在 {_format }

中有多余的空格

path: /{id}/first.{_format }

尝试删除它