Question

I would like to get POST data sent to page controller in init() function but what I get is an empty array.

However, getting getRawBody displays data.

Here is the command I use:

curl http://localhost/api/page/7 -X PUT -d "test=true"

and the output is:

Array ( ) test=true

class Api_PageController extends Zend_Rest_Controller
{
    public function init()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->layout->disableLayout();
        print_r($this->getRequest()->getPost());
        print_r($this->getRequest()->getRawBody());    
    }
}
Was it helpful?

Solution

What you want is the PutHandler plugin. This will make POST and PUT use the same getParams();

put this in your application.ini

resources.frontController.plugins.putHandler = Zend_Controller_Plugin_PutHandler

Then the data should appear when you call

$this->getRequest->getParams();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top