views:

30

answers:

1

I have a action that returns a JSON and i need to call it from another controller and i need to get this response into a variable to parse the json.

i've tried:

private function makeListFromUrl($menu)
{
    $req = new Zend_Controller_Request_Http();
    $req->setRequestUri('/module/controller/get.json/');

    $res = new Zend_Controller_Response_Http();
    $dis = $this->getFrontController()->dispatch($req, $res);

    $dis->dispatch($req, $res);

    $json = $res->getBody();

    return Zend_Json::decode($json);
}

but this code makes the front to render the action, overriding the actual action. i just want to make a request, and get the response into a variable, leaving the actual request untouched.

thanks

A: 

i have a simple solution to this, not sure if it's the best, but worked very well.

$actionHelper = new Zend_View_Helper_Action();

$var = $actionHelper->action('action', 'controller', 'module', $params);

same way you'd do inside the view, but in the controller.

i hope this can help somebody.

chsegala