0

I am very newbie in zend framework, I send some data to an action with post method by this way:

$config = array(
    'adapter'   => 'Zend_Http_Client_Adapter_Curl',
);

$client = new Zend_Http_Client('http://example.com/api/last-news', $config);
$client->setParameterPost('name' ,'value');
$dataresult = $client->request('POST')->getBody();

when In lastNewsAction() action in ApiController.php I use var_dump($_POST) it's passed me empty array, but when I send those data to a simple file out of framework(something like http://example.com/test.php) the $_POST has correct value. SO How can I retrieve $_POST variable in an action?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Arash Mousavi
  • 2,110
  • 4
  • 25
  • 47
  • 1
    Usually `$this->getRequest()->getParam('var-name');` works – Keyne Viana Sep 06 '12 at 17:38
  • If your action is returning a NULL value for the $_Request object then the data is not getting to the action. Check and make sure your urls are valid and correct. Unless you have redefined your routes the url you are trying to reach would be the *ApiController* and *lastNewsAction*. That's your starting place. POST anything, just to make sure the route works. – RockyFord Sep 07 '12 at 02:18

1 Answers1

2

Or if you want them all...

if ($this->getRequest()->isPost()) {        
    $postData = $this->getRequest()->getPost();
    ...
ficuscr
  • 6,975
  • 2
  • 32
  • 52
  • when I var_dump($this->getRequest()->getPost()) it returns array(0){}. – Arash Mousavi Sep 06 '12 at 17:50
  • and also var_dump($this->getRequest()->isPost()) returns bool(false). – Arash Mousavi Sep 06 '12 at 17:58
  • Well you are not getting a POST then. What does the super global $_REQUEST show? Use a tool like HTTP Headers browser extension to see what's going on. – ficuscr Sep 06 '12 at 18:09
  • Your API controller simply extends `Zend_Controller_Action`? Your not doing something with `Zend_Rest_Route` or something? Need to understand better how you are handling the request to suggest where you might be unsetting the _POST. – ficuscr Sep 06 '12 at 18:21
  • $_REQUESt is null, too... I test with HTTP RESOUCE tool(firefox extension) , nothing happend. API Controller exteds from Zend_Controller_Action, let met check Zend_Rest_Route... – Arash Mousavi Sep 06 '12 at 18:43
  • I'm not found Zend_Rest_Route anywhere in project. – Arash Mousavi Sep 06 '12 at 19:00
  • Really sounds then like its on the client end. If for example `var_dump($_POST);` in your app's index.php file is empty you are certainly not successfully posting. Might be due to a redirect. Perhaps check the 'strictredirects' setting for the `Zend_Http_Client`. – ficuscr Sep 06 '12 at 19:08
  • in index.php `$client = new Zend_Http_Client('http://example.com/index.php', $config)` its returns $_POST variable correctly, but `$client = new Zend_Http_Client('http://example.com/api/last-news', $config)` doesnt work. I check it hasn't any redirect from http://example.com/api/last-news... – Arash Mousavi Sep 08 '12 at 08:04