0

I'm trying to create a custom http method in RESTful API. I was reading the documentation and it is said that you can do it buy adding a simple action in controller and then for example conifg your route with child routes with action => action_name but in the code I have spotted addHttpMethodHandler() method in Zend\Mvc\Controller\AbstractRestfulController.php so in controller construct method I have added:

$add = function () {
        return new JsonModel(array(
                'id' => 2222,
        ));
    };

    $this->addHttpMethodHandler('someAction', $add);
    var_dump($this->customHttpMethodsMap);

With the var_dump I can see that this new function is added but I just wonder how can I call it or maybe I'm missing the point.

Regards,

4

1 回答 1

2

实际上,我为此写了一篇博客文章,因为我也遇到了很多麻烦。

问题在于,除了在抽象的 restful 控制器中调用 addHttpMethodHandler 之外,您还需要确保 Zend Request 类知道您的 http 方法存在。

这是一个更好解释的链接:http ://richardbrock1.wordpress.com/2013/03/23/custom-http-methods-in-zf2/

于 2013-04-02T02:27:13.777 回答