我正在尝试在 Kohana 3.2 中创建一个匹配 URI 的路由,例如
api/article/get.json
api/article/get/123.xml
api/blogpost/post.json
api/user/get/username.json
所以我的想法是我有一个名为 API 的子目录,其中有我所有的 api 控制器,路由匹配控制器、方法、格式,或者和 id。
我在我的application/bootstrap.php
Route::set('api', 'api/<controller>(/<action>(/<id>).<format>)',
array(
'format' => '(xhtml|xml|json|rss|html|php|serialize)',
))
->defaults(array(
'directory' => 'api',
'controller' => 'blogposts',
'action' => 'get',
'format' => 'json',
));
我玩过这条路线的多种组合,但每次我收到以下错误消息,例如:localhost/api/blogposts/post.json
HTTP_Exception_404 [ 404 ]: The requested URL api/blogposts/post.php was not found on this server.
在我看来,这应该没问题,但我一定做错了什么。
帮助表示赞赏。
梦间
编辑
我的默认控制器设置为最后一个,只是想我会提到它,因为我在 SO Kohana 3 route not matching中发现这篇文章