How can I check if request is post in Zend Framework

29,736

Solution 1

$this->getRequest() in the context of a controller is annoted to return an object of class Zend_Controller_Request_Abstract. isPost() is a method of Zend_Controller_Request_Http which is derived from Zend_Controller_Request_Abstract.
So your IDE cannot offer this method, but it is there.

Solution 2

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

Solution 3

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

isPost() should be there too, though, I don't know why you don't find it.

Solution 4

if($this->_request->isPost){
echo "Values is POST"; 
}
else
{
 echo "Try again";
}

I just learnt it. Yepppiiiiiiiiii !!!!!!!!!!

Share:
29,736

Related videos on Youtube

Jiew Meng
Author by

Jiew Meng

Web Developer & Computer Science Student Tools of Trade: PHP, Symfony MVC, Doctrine ORM, HTML, CSS, jQuery/JS Looking at Python/Google App Engine, C#/WPF/Entity Framework I hope to develop usable web applications like Wunderlist, SpringPad in the future

Updated on July 09, 2022

Comments

  • Jiew Meng
    Jiew Meng almost 2 years

    I remember using something like

    $this->getRequest()->isPost()
    

    but it seems like there isn't such a function. How can I check if the request is post so I can validate the form etc

    • Phil
      Phil over 13 years
      In which context? Your code snippet above should work fine in a controller
  • Phil
    Phil over 13 years
    Great answer. One thing you can do is add an inline var type comment, eg /* @var $request Zend_Controller_Request_Http */ then fetch the controller request object into a $request variable, eg $request = $this->getRequest(). If using Netbeans or a PDT based IDE, you should get the code completion for the HTTP class.
  • Jakob Alexander Eichler
    Jakob Alexander Eichler over 12 years
    that's what ZF does internally.

Related