所以,我有一个zend rest API并且我实现了Zend_Rest_Controller,应用程序可以工作,但是url方案对我来说很奇怪。
www.example.com/public/user <- triggers index action in my UserController
www.example.com/public/user/get <- triggers get action in my UserController
www.example.com/public/user/post <- triggers post action in my UserController
www.example.com/public/user/put <- triggers put action in my UserController
www.example.com/public/user/delete <- triggers delete action in my UserController
此外,API有点响应请求,就像你要用POST进行ajax调用并输入post参数,然后api可以获取参数,但不关心它是POST,所以如果我打电话给www.example.com/public/user并输入POST参数,然后API认为它调用了索引操作但是带有我可以访问的参数
$this->getRequest()->getParam()
让网址更像是
会很高兴www.example.com/user <- And have it respond to requests like POST or GET
任何人都知道为什么我的网址架构如此奇怪?
答案 0 :(得分:0)
您应该在Zend配置中设置REST路由。这可以这样实现:
$front = Zend_Controller_Front::getInstance();
$restRoute = new Zend_Rest_Route($front, array(), array(
'public' => array('user')
));
$front->getRouter()->addRoute('rest', $restRoute);
这将导致Public_UserController():
GET /public/user - IndexAction
POST /public/user - postAction
PUT /public/user/:id - putAction
DELETE /public/user/:id - deleteAction
另请参阅Zend Framework文档的这一部分:http://framework.zend.com/manual/1.12/en/zend.controller.router.html#zend.controller.router.routes.rest
我还想补充一点,使用Zend_Config INI配置REST路由可能最终会进行某种故障排除,因为报告了一些关于REST路由和INI配置的错误。另见: