Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: Zend_Layout
-
Labels:None
-
Tags:
Description
This is partly a Zend_Layout issue and partly a problem with ViewRenderer helper, I think.
Suppose one is using Zend_Layout with the ActionStack, as recommended in the docs, and the stack is set up at dispatchLoopStartup (which seems like the right place for it). Content from these actions is assigned to response segments using $this->_helper->viewRenderer->setResponseSegment('someSegment'), in order that it can be rendered in the correct place by Zend_Layout.
I want to disable the layout in one of my actions; however, when I do so (using $this->getHelper('layout')->disableLayout()) , any actions previously called by the ActionStack are then appended to the body - there are no layout placeholders (as layout is disabled), and so these items are simply tagged on to the main body. This is not, I believe, appropriate behaviour.
Psuedo-code may clarify:
function dispatchLoopStartup
{
$actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
$menuAction = clone($request);
$menuAction->setActionName('menu')
->setControllerName('my_controller');
$actionStack->pushStack($menuAction);
}
function menuAction
{
// stuff ...
// menu viewscript renders like <div id=menu>menu item 1, menu item 2</div>
$this->_helper->viewRenderer->setResponseSegment('menu');
}
function withLayoutAction
{
// stuff ...
// withLayout viewscript renders like <div id=withLayout>some with-layout text</div>
}
function noLayoutAction
{
$this->getHelper('layout')->disableLayout();
// stuff
// noLayout viewscript renders like <div id=noLayout>Some no-layout stuff here</div>
}
<H1>Menu</H1> <?= $this->layout()->menu ?> <H1>Main Content</H1> <?= $this->layout()->content ?>
If I go to my_controller/withLayout, I get the menu and withLayout div rendered at the layout placeholders as you'd expect, no problem.
If I go to my_controller/noLayout, I the full output is:
<div id=noLayout>Some no-layout stuff here</div><div id=menu>menu item 1, menu item 2</div>
The content from menuAction is simply appended to the content from noLayoutAction, which is exactly not what I want!
One workaround is rather than disable the layout, to use a layout template with only the 'content' placeholder:
<?= $this->layout()->content ?>
and then, rather than disabling the layout, change layout script in the controller action
function noLayoutAction
{
$this->getHelper('layout')->setLayout('no-layout');
}
This implies to me that a possible fix would be to never actually disable Zend_Layout, but instead force it to use a basic layout template as above; to rewrite disableLayout:
public function disableLayout() { $this->setLayout('no-layout'); $this->_enabled = false; return($this); }
Markup edit for readability.