Zend_Rest_Route对于特定的控制器 [英] Zend_Rest_Route for a specific controller

查看:281
本文介绍了Zend_Rest_Route对于特定的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个Zend_Rest_Route为特定的控制器。我希望我的网站的其余正常行为,当请求特定的控制器(UploadAPI)除外。我认为sytnax应该如下,但有一个很难核实。这些例子都与模块做的,但我没有一个模块。
它是否正确?

I'm trying to make a Zend_Rest_Route for a specific controller. I want the rest of my site to behave normally, except when a particular Controller (UploadAPI) is requested. I think the sytnax should be as follow, but having a hard time verifying. The examples all have to do with modules, but I don't have a module. Is this correct?

protected function _initRestRoute() {
    $this->bootstrap('frontController');
    $frontController = Zend_Controller_Front::getInstance();
    $restRoute = new Zend_Rest_Route($frontController, array(), array('default' => array('UploadAPI'),));
     $frontController->getRouter()->addRoute('rest', $restRoute);
}

下面的链接

<一个href=\"http://weierophinney.net/matthew/archives/228-Building-RESTful-Services-with-Zend-Framework.html\" rel=\"nofollow\">http://weierophinney.net/matthew/archives/228-Building-RESTful-Services-with-Zend-Framework.html

给人以模块的例子,但我没有模块,和我假设默认是模块的名字。

gives examples with modules, but I have no modules, and am assuming "default" is the module name.

推荐答案

所以我有API功能的工作,这是它的外观。你必须在引导类添加此功能,用来初始化Zend_Rest_Route。
这将只做数组中列出的控制器,该网站的其余部分应该按预期工作了Zend REST API路由

So I have the API functionality working , this is how it looks. You have to add this function in Bootstrap class to initilize Zend_Rest_Route. This will do the Zend Rest API routing only for the controllers listed in the array, the rest of the site should work as expected

protected function _initRestRoute() {
  $this->bootstrap('frontController');
  $frontController = Zend_Controller_Front::getInstance();
  $restRouteUL = new Zend_Rest_Route($frontController, array(), array('default' => array('UploadAPI', 'LocationMatchesAPI', 'GetMatchesByIdAPI', 'AuthAPIController')  ));
$frontController->getRouter()->addRoute('rest', $restRouteUL);
}

这篇关于Zend_Rest_Route对于特定的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆