I'm using various modules and a parent controller to keep consistancy.
My parent controller has a bunch of common actions that each of the subsequent child controllers need to have access to. I'm finding it difficult to make this default action render a correct view.
I do NOT want to have to add the same view to each of my modules - that would defeat the object - but i would like to have a default view somewhere.
I have tried:
$this->_forward('commonaction', 'baselayout', 'default');
This doesnt work for me - as it tries to process the action again - when i've already populated the variables needed within my parent controller.
Any help would be awesom.
UPDATE:
To clarify i want to be able to use a common view from a different module. All exampels and solutions currently assume a common module. THis doesnt work for me.
I fixed it by using:
$this->_helper->viewRenderer->renderBySpec('foo', array('module' => 'modulename', 'controller' => 'controllername'));
Use this statement in your controller:
// Render 'foo' instead of current action script
$this->_helper->viewRenderer('foo');
// render form.phtml to the 'html' response segment, without using a
// controller view script subdirectory:
$this->_helper->viewRenderer('form', 'html', true);
from the official doc http://framework.zend.com/manual/en/zend.controller.actionhelpers.html
It is not possible (at the best of my knowledge) to show view of different module. Besides there's no trace of this question in the official doc.
Like you, I have multiple modules and wanted to render an arbitrary view (residing in one module) in the controller of a different module.
This was the only way that I could get it to work, after trying many approaches:
Controller action:
public function xyzAction()
{
$this->_helper->layout->disableLayout();
$view = new Zend_View();
$view->setScriptPath(APPLICATION_PATH . '/modules/moduleB/views/scripts/abcBlahBlah');
echo $view->render('yadaYada.phtml');
exit;
}
Try the following in your action:
See the following code:
// Add a script path to the directory in the other module
$this->view->addScriptPath(APPLICATION_PATH . '/modules/baselayout/views/scripts');
// Tell the viewRenderer to use the view script 'scriptname'
$this->_helper->viewRenderer('scriptname');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With