views:

69

answers:

2

Hi there,

I have the following setup:

An endless running PHP process that looks at a job queue which contains module names, controller names, action names and a parameter array.

For every job I want to call the given controllers action and retrieve the rendered view for further processing.

I was thinking about bootstrapping an instance of Zend_Application for every job but not exactly sure on how to handle the rest. Maybe there is also a better way.

So my question is:

How do I call other Controllers within a Zend Framework Process and retrieve their rendered view?

Thanks to everyone in advance!

A: 
$this->_forward('otherAction', 'otherControllerOrNull');

http://framework.zend.com/manual/en/zend.controller.dispatcher.html

You can read this thread : http://stackoverflow.com/questions/886291/calling-member-function-of-other-controller-in-zend-framework

Julien CROUZET
But this would forward the existing request to the specified controller/action, right? It sounds to me like OP wants to capture the output from that controller/action for use in the *current* request.
David Weinraub
Thats right David, I want to keep the current process running and just work with whatever output has been produced by the other controller. _forward will not allow this.
favo
+1  A: 

I would think taking the Front_Controller and dispatching a new request would be the best to do.

Something like this, from your controller (not working code):

    $frontController = $this->getFrontController();

    $newRequest = new Zend_Controller_Request_Http();
    $newRequest->setActionName('newAction');
    $newRequest->setControllerName('newController');

    $response = new Zend_Controller_Response_Http();

    $frontController->dispatch($newRequest, $response);

It might not be this simple, but something to think about...

spankmaster79
it worked: $request = new Zend_Controller_Request_Http();$this->getFrontController()->setResponse(new Zend_Controller_Response_Cli)->setRequest($request->setControllerName('testController')->setActionName('testAction'))->setRouter(new Zend_Controller_Router_Route)->setParam('noViewRenderer', true); … thank you! :-)
favo