I found this code here while trying to understand what an actionstack does and why they’re supposed to be so bad. I thought that an actionstack is just one type of action helper (just like flashmessenger or redirector or ViewRenderer).
But anyway, does anyone understand what this code does and how to do the same thing without an actionstack?
class MyController_Action extends Zend_Controller_Action {
function init() {
/** you might not want to add to the stack if it's a XmlHttpRequest */
if(!$this->getRequest()->isXmlHttpRequest()) {
$this->_helper->actionStack('left', 'somecontroller', 'somemodule');
$this->_helper->actionStack('center', 'somecontroller', 'somemodule');
$this->_helper->actionStack('right', 'somecontroller', 'somemodule');
}
}
class MyController extends MyController_Action {
function indexAction() {
// do something
}
}
class SomecontrollerController extends MyController_Action {
function leftAction() {
// do something
$this->_helper->viewRenderer->setResponseSegment('left_container');
}
function centerAction() {
// do something
$this->_helper->viewRenderer->setResponseSegment('center_container');
}
function rightAction() {
// do something
$this->_helper->viewRenderer->setResponseSegment('right_container');
}
}
I’d implement the actions as re-usalbe widgets (action helpers with
preDispatch()methods), as described here:Using Action Helpers To Implement Re-Usable Widgets – phly, boy, phly
The widgets may render the output into
placeholderview helpers, and so be used anywhere in the layoutThey may also render the content into other
placeholder, e.g. sidebar, like described in the manual:The other solution is to use view helpers, which access the model data, and run them in the layout.