从另一个动作控制器调用Zend_Rest Action的最佳方法

时间:2013-04-22 08:25:20

标签: api zend-framework rest controller action

我在Zend(1.12)应用程序中设置了一个“Api”模块,该模块与Rest一起工作。 因此,在该模块中,控制器扩展Zend_Rest_Controller。它工作正常,从终端或ajax调用使用它非常有用。每个Controller都返回json。

只是Rest Controller的一个简单示例:

class Api_NewsController extends Zend_Rest_Controller
{
...
    public function postAction()
    {
        $param = $this->getRequest()->getParams();
        $news = new Api_Model_News();
        $insert = $news->insert($param['id']);
        $this->getResponse()->appendBody( json_encode($param) );
    }
....

在终端的卷曲中使用它

curl -v http://example/api/news/123

从jQuery ajax中使用它

$.post("http://example/api/news", { "id": 123 },
    function(data){}, "json");

但现在的目标是从另一个控制器(来自另一个模块)调用Rest postAction 。 最好的方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以使用View Helper“操作”:http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action

或者使用“正确的”API方式并使用curl?

相关问题