Thanks for that.

That's part of the problem, certainly, and your workaround will solve the
problem - however, one of the main goals for Zend_Layout is "Allow disabling
layouts ... from within action controllers and view scripts."

The other part of the problem is that actions which are rendered to a
response segment using setResponseSegment are rendered regardless of whether
there's a placeholder to accept them - but only if there are *no*
placeholders at all.  (not sure of the terminology here, but I think my
sentiment is clear).  The default behaviour is to render all response
segments to the main body content, and I believe that's inappropriate.

My other workaround (just invented, but working) illustrates this:
create a layout like

no-layout.phtml:
<?= $this->layout()->content ?>

and then
function noLayoutAction
{
  $this->getHelper('layout')->setLayout('no-layout');
}

Since there is a 'content' placeholder but no 'menu' placeholder,
noLayoutAction is rendered but menuAction is not.  (It would be better if
menuAction was not run, for performance reasons, but I don't see how to
achieve that).


I'm going to file this as a bug report, I think.  Thanks for your help!

Mark





Ionut Gabriel Stan-2 wrote:
> 
> Your problem has little to do with Zend_Layout. The issues resides in 
> the fact
> that MyPlugin::dispatchLoopStartup() will be called regardless of 
> whether or not
> you've disabled Zend_Layout in a certain action. That's why 
> MyController::menuAction()
> will always be executed, as it will always be on the action stack.
> 
> One way to solve this is to have a check in your 
> MyPlugin::dispatchLoopStartup(), like this:
> 
>      public function 
> dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
>      {
>          if ($request->getActionName() === 'no-layout') {
>              return;
>          }
>      }
> 
> There probably are better ways to do this, but I have no other idea for 
> the moment.
> Hope it helps somehow.
> 
> Cheers
> 
> On 5/5/2009 13:09, lightflowmark wrote:
>> Hi - thanks for taking a look at this.
>>
>> I think the relevant parts of the code are:
>>
>> In my Front Controller Plugin:
>>    function dispatchLoopStartup
>>    {
>>              $actionStack =
>> $front->getPlugin('Zend_Controller_Plugin_ActionStack');
>>              $menuAction = clone($request);
>>              $menuAction->setActionName('menu')
>>                      ->setControllerName('my_controller');
>>              $actionStack->pushStack($menuAction);
>>    }
>>
>> In MyController:
>>    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>
>>    }
>>
>> In layout.phtml:
>> <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!
>>
>> I'm not sure if I'm doing something wrong, or if this is somehow desired
>> behaviour, or whether this is in fact broken.
>>
>> Thanks,
>> Mark
>>    
> 
> -- 
> Ionut G. Stan
> I'm under construction  |  http://igstan.blogspot.com/
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Disabling-Layout-with-ActionStack-causing-problems--tp23383426p23385484.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to