看看在链接的文档中给出的示例路由模式,嵌套Articles
>Comments
资源将创建路线Comments
与以下模式:
/articles/:article_id/comments
/articles/:article_id/comments/:id
您还可以检查$ bin/cake routes
获取列表所有连接路线的模式和默认值。你要找的路线将在那里列为是这样的:
+----------------+--------------------------------+--------------------------------------------------------------------------+
| Route name | URI template | Defaults |
+----------------+--------------------------------+--------------------------------------------------------------------------+
| comments:index | /articles/:article_id/comments | {"controller":"Comments","action":"index","_method":"GET","plugin":null} |
路由绑定到特定的HTTP方法(如上面可以在默认列中可以看出)的所有资源,即内部的_method
选项使用,并且父ID以前缀单数控制器/资源名称为前缀。
要匹配Comments
索引,只需将Comments
控制器和index
按照常规操作即可。另外通过相应_method
(对于index
这GET
),并通过父ID在名为方式,即作为article_id
,如:
[
'controller' => 'Comments',
'action' => 'index',
'_method' => 'GET',
'article_id' => 4
]
参见
来源
2017-05-30 12:59:52
ndm
非常感谢!解决方案非常简单 – jurrieb