如何检查请求是否在Zend Framework中发布

Jie*_*eng 22 zend-framework

我记得用过类似的东西

$this->getRequest()->isPost()
Run Code Online (Sandbox Code Playgroud)

但似乎没有这样的功能.如何检查请求是否发布,以便我可以验证表单等

Max*_*nce 41

$this->getRequest()在控制器的上下文中注释为返回类的对象Zend_Controller_Request_Abstract.isPost()是一种Zend_Controller_Request_Http从中衍生出来的方法Zend_Controller_Request_Abstract.
所以你的IDE不能提供这种方法,但它就在那里.

  • 很好的答案.您可以做的一件事是添加内联var类型注释,例如`/*@var $ request Zend_Controller_Request_Http*/`然后将控制器请求对象提取到`$ request`变量,例如`$ request = $ this-> getRequest( )`.如果使用Netbeans或基于PDT的IDE,您应该获得HTTP类的代码完成. (7认同)

Kde*_*com 16

if ($this->getRequest()->isPost()) 
{
    echo "this is post request";
} 
else 
{ 
    echo "this is not the post request";
}
Run Code Online (Sandbox Code Playgroud)


Sta*_*asM 9

   if($this->getRequest()->getMethod() == 'POST') {
       echo "You've got post!";
   }
Run Code Online (Sandbox Code Playgroud)

isPost()也应该在那里,但我不知道为什么你找不到它.