我使用默认的Zend_Rest_Route来生成Rest路由:
因此,我只是放在resources.router.routes.rest.type = Zend_Rest_Routeapplication.ini中,现在为用户提供Rest Routes
GET users
POST users
GET users/:id
GET users/:id/edit
PUT users/:id
DELETE users/:id
Run Code Online (Sandbox Code Playgroud)
但嵌套资源怎么样?鉴于我需要
users/:user_id/articles
users/:user_id/articles/:id
... etc
Run Code Online (Sandbox Code Playgroud)
有没有办法保持路线REST'y?将欣赏创建此类嵌套路由的任何示例
PS我正在使用ZF版本1.10.8
问候,M
我使用zend框架来构建REST Web服务,我正在使用模块来分离我的api版本,正如我在这里提到的那样
例如:"applications/modules/v1/controllers","applications/modules/v2/controllers"具有不同的操作和功能集.我在application.ini中提到了我的默认模块"v1"
我使用的上下文正如我刚才所说随着正则表达式路由交换这里我接受的解决方案:
$router->addRoute(
'route1',
new Zend_Controller_Router_Route_Regex(
'api/([^-]*)/([^-]*)\.([^-]*)',
array(
'controller' => 'index',
'action' => 'index'),
array(
1 => 'module',
2 => 'controller',
3 => 'format'
)
));
Run Code Online (Sandbox Code Playgroud)
这是我的网址:http://localhost/api/v1/tags.xml
"v1"表示模块.现在,进入上下文切换,如果url有v1,它将转到v1模块的TagsController.但是如果url中的模块是v2,我会收到如下错误:
在此服务器上找不到请求的URL /pt/public/index.php/api/v2/tags.xml.
我无法理解为什么它会炸毁.是因为我把默认模块设为v1吗?我无法根据网址更改模块.
这是我的目录树: