【发布时间】:2017-02-01 22:27:42
【问题描述】:
我不明白一个问题。 当使用带有路由示例的控制器时
/**
* @Route("/news/comment-delete/{comment_id}",
* name = "blog_deleteComment"
* )
* @ParamConverter("comment", class="pfrechowiczBlogBundle:Comment", options={"id" = "comment_id"})
*/
并在 HTML 中为控制器提供参数
<a href="{{ path('blog_deleteComment', {'comment_id' : comment.id}) }}" class="blog_deleteComment" >Usuń</a>
它工作正常,但是当我将“_”更改为“-”时它不起作用,我不知道为什么找不到答案。只有当必须使用带有“-”的 URL 的 ParamConverter 而没有使用“-”的 ParamConverter 的 Route 时才会出现此问题。
这个例子不起作用:
/**
* @Route("/news/comment-delete/{comment-id}",
* name = "blog_deleteComment"
* )
* @ParamConverter("comment", class="pfrechowiczBlogBundle:Comment", options={"id" = "comment-id"})
*/
和 HTML 代码:
<a href="{{ path('blog_deleteComment', {'comment-id' : comment.id}) }}" class="blog_deleteComment" >Usuń</a>
有人能解释一下吗?
【问题讨论】:
-
如果您的网址看起来像:
/news/comment-delete/12345 -
“不工作”是什么意思?您是否收到有意义的错误消息,或者它只是无法解析 URL 并静默失败?我之所以问,是因为这可能是 symfony 可以改进的地方,它是“DX 倡议”的术语
-
它的消息无法识别它是什么类型的对象
标签: php controller routing symfony