2

I have referred many articles in the web on this subject but got only basic examples. I got some practical issues.

1). In Zend_Rest_Controller there are abstract methods for get, post, put and delete. how do I create my own function rather thean using getAction, postAction, etc... in order to respond for a get request (Ex: api.abc.com/product/5 - That will return set of products from a category 5)?

2). Is it possible to enable rest routing only for a specific controller in a module?

Can you give some example or some article?

4

1 回答 1

0

我将尝试回答这个问题,因为我已经使用Zend_Rest_Controller.

1)那么你应该使用这些方法。它们很有帮助,因为它们会迫使您将每个控制器都视为一种资源来思考。因此,对于每个资源,您应该只能定义一次 GET 动词。

public function getAction()
{
    if (!is_null($this->getParam("id"))) {
        $this->view->user = $userModel->getUserById($this->getParam("id",null));
        $this->_helper->viewRenderer('get-user');
    } else {
        $userModel = new Model_Users();
        $this->view->users = $userModel->getUsers();
        $this->_helper->viewRenderer('get-all-users');
    }
}

2)开箱即用 - 我认为没有。但这应该不是一件坏事,因为无论如何您都应该将所有其余功能放在一个单独的模块中。

于 2014-11-11T15:37:32.600 回答