Jiew Meng
Jiew Meng

Reputation: 88197

How can I check if request is post in Zend Framework

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

Upvotes: 23

Views: 30563

Answers (6)

DMCoding
DMCoding

Reputation: 1237

Not all ZendFramework applications instantiate a Request instance into the Controller. For SocialEngine, the following works:

<?php
    if (Zend_Controller_Front::getInstance()->getRequest()->isPost()) {
        ...
    }

Upvotes: 0

Rushit
Rushit

Reputation: 526

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

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

Upvotes: 1

Kdecom
Kdecom

Reputation: 728

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

Upvotes: 17

Maxence
Maxence

Reputation: 13296

$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.

Upvotes: 43

Awais Usmani
Awais Usmani

Reputation: 188

if($this->getRequest()->isPost()) echo "this is post request";

Upvotes: 0

StasM
StasM

Reputation: 11032

   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.

Upvotes: 10

Related Questions