我正在为 REST 服务编写一些路由。我的资源的一个 URI 看起来像这样
资源/用户/:id
我还想访问用户的各个属性,看起来像这样
资源/用户/:id/:属性
但是当我尝试定义后一条路线时,它不起作用。这是我定义路由的ini
routes.user.route = "resources/user/:id"
routes.user.defaults.controller = user
routes.user.defaults.action = get
routes.user.defaults.id = 0
routes.user.reqs.id = "\d+"
routes.user_attribute.route = "resources/user/:id/:attribute/"
routes.user_attribute.defaults.controller = user
routes.user_attribute.defaults.action = getAttribute
routes.user_attribute.defaults.id = 0
routes.user_attribute.defaults.attribute = ""
routes.user_attribute.reqs.id = "\d+"
routes.user_attribute.reqs.id = "reviews|lists"
当我尝试在浏览器中访问 resources/user/4/reviews 时,我得到以下输出
An error occurred
Page not found
Exception information:
Message: Invalid controller specified (resources)
Stack trace:
#0 /usr/local/lib/ZendFramework/ZendFramework-1.7.1-minimal/library/Zend/Controller/Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 /home/baileyp/public_html/web/index.php(50): Zend_Controller_Front->dispatch()
#2 {main}
Request Parameters:
array(4) {
["controller"]=>
string(9) "resources"
["action"]=>
string(4) "user"
[10]=>
string(7) "reviews"
["module"]=>
string(7) "default"
}
因此,它显然没有正确处理我的第二条路线,因为控制器是“资源”而操作是“用户”。我在这里做错了什么?我发现 Zend 站点上没有任何示例可以说明如何实现这一点。
而且我不想使用模块来完成这项工作 - 避免创建文件夹等只是为了匹配 URI 是路由系统的全部目的。