开发者

Zend Routes and HTTP Verb/Method

开发者 https://www.devze.com 2023-03-09 11:23 出处:网络
Hi I am trying to setup some REST routes in a Zend app, I am wondering how I can restrict the HTTP method on which the route can be accessed.

Hi I am trying to setup some REST routes in a Zend app, I am wondering how I can restrict the HTTP method on which the route can be accessed.

$route = new Zend_Controller_R开发者_开发百科outer_Route('user/reset_password', array(
                'module' => 'default',
                'controller' => 'user',
                'action' => 'resetpassword'
            ));
$front_controller->getRouter()->addRoute('reset_password', $route);

In this route I would like to specify the HTTP verb like GET, POST, PUT, etc that this route will respond to, such as adding "method" => "POST" to the array.

Thanks,


You cannot do that in the current implementation of ZF since it declares route interface as:

interface Zend_Controller_Router_Route_Interface {
    public function match($path);
    public function assemble($data = array(), $reset = false, $encode = false);
    public static function getInstance(Zend_Config $config);
}

As you can see there is no room for method parameter.

However, you could do all the checks, say, in the controller or write your own router.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号