Right. I actually got rid of the $this->action() and put the action stack back, because I felt it was cleaner to not have to pass the action parameters around, but have it run in the context of the actual action itself. So I am using the response segment again.
But, I do see what you are getting at, and in fact I was wondering something similar myself. I have one action in my controller that outputs two different pages depending on whether I am looking at a set of race dates, or a set of results for that race date, as you can see on my site (a simple site I am building to learn ZF): http://www.outbackraceway.com/index/results http://www.outbackraceway.com/index/results/date/01-10-2009 Right now my results.phtml file checks if a date is present, and uses a partial to render that portion, and a different partial when there is no date (ie: _resultsAll.phtml and _resultsSingle.phtml). Which I don't really like because then my results.phtml file contains logic to render the two partials, and the real layout is in the partials. So my results.phtml looks like this: <?php if (isset($this->date)) { $this->headTitle('Race Results for ' . $this->date); echo $this->partial('index/_resultsSingle.phtml', array('date' => $this->date, 'results' => $this->results)); } else { $this->headTitle('Race Results'); echo $this->partial('index/_resultsAll.phtml', array('results' => $this->results)); } ?> I thought about having a totally separate action for the all results page, and the single results page, but that seems like too much overhead to me, as they do have some commonality (they are just different renderings of the same page), and more importantly, if I have a separate main action, then my menu gets confused because it highlights the item in the menu depending on which action is being processed. So what I was trying to do, and could not figure out, is to somehow set a totally different view script to be rendered in my resultsAction() controller method. Not quite a response segment, as that just sends the data to a different section of the view for later rendering, but rather to change the file that will be used to render the view. So then I could do away competely with my results.phtml file that calls the two partials, and instead just have resultsSingle.phtml and resultsAll.phtml and select which one I want to render to in my resultsAction() method. Not sure that is exactly what you are trying to do, but it sounds similar :) Regards, Kendall Bennett, CEO A Main Hobbies 424 Otterson Drive, Suite 160 Chico, CA 95928 1-800-705-2215 (Toll-Free) 1-530-894-0797 (Int'l & Local) 1-530-894-9049 (Fax) http://www.amainhobbies.com ________________________________ From: Mark <[email protected]> Date: Mon, 4 May 2009 00:43:27 -0700 To: Kendall Bennett <[email protected]> Subject: Re: [fw-general] Zend_Layout for individual actions? Hi Kendall, Thanks for that. I've simplified my example; partials are not the way forward in this instance, although I take your point about the overhead, and do use them where appropriate. There's a large performance hit in using $this->action() over the ActionStack, which is why I don't use it, although it would solve the problem. See the Zend Performance Guide in the manual for details on this, if it's of interest. The alternate solution you've outlined, using setResponseSegment, only works for the global layout - I use it to render the menu and the header, in my example. At least, I can only make it work for the global layout. I've been unable to make setResponseSegment render widgetAction & anotherWidgetAction to placeholders within index.phtml - only to placeholders within layout.phtml. Yours, Mark Kendall Bennett wrote: Re: [fw-general] Zend_Layout for individual actions? For starters it is a bit of extra overhead to use a separate layout to render the header and footers, so instead the simple solution is to use partials. The core of my layout looks like this (HTML formatting cruft removed): <?php echo $this->partial('_header.phtml'); ?> <?php echo $this->action('menu', 'index', null, array('currentAction' => Zend_Controller_Front::getInstance()->getRequest()->getParam('action'))); ?> <?php echo $this->layout()->content; ?> <?php echo $this->partial('_footer.phtml'); ?> Note that rather than using an actionStack event to render my menu, I decided to avoid all that cruft and instead use the $this->action() helper to render the menu using my menuAction. Note that I also extact the current action request parameters and pass it to my menuAction, so the menu can determine which of the main actions is being rendered, and can highlight it. The other alternate, and the one I think you are looking for, is to use the actionStack. If you do it that way, you simply need to change the response segment in the controller action code right before you exit, to give it the name of the segment you want it to be rendered it, like so: // Tell the renderer to render it to a different response segment $this->_helper->viewRenderer->setResponseSegment('menu'); Regards, Kendall Bennett, CEO A Main Hobbies 424 Otterson Drive, Suite 160 Chico, CA 95928 1-800-705-2215 (Toll-Free) 1-530-894-0797 (Int'l & Local) 1-530-894-9049 (Fax) http://www.amainhobbies.com ________________________________ From: lightflowmark <[email protected]> Date: Sun, 3 May 2009 08:32:27 -0700 To: Zend Framework General <[email protected]> Subject: [fw-general] Zend_Layout for individual actions? Hi, I'm trying to achieve the following and having real difficulty in seeing how it should work: 1) have a global layout using Zend_Layout which renders some common-to-all-actions stuff - a header, a menu, a footer. The 'main action' is then rendered to layout()->content. 2) have the 'main action' render some widget actions to placeholders within its view script. So if I have the following IndexController: menuAction headerAction indexAction widgetAction anotherWidgetAction layout.phtml: <?= $this->layout()->header ?> <?= $this->layout()->menu ?> <?= $this->layout()->content ?> index.phtml: <? //I want widgetAction content rendered here ?> <? //I want anotherWidgetAction content rendered here ?> When I go to /index/index, menuAction and headerAction are called by the ActionStack and rendered at the appropriate placeholders in layout.phtml by Zend_Layout. Then I want indexAction to call widgetAction and anotherWidgetAction and render them to placeholders within index.phtml. What is the best way of achieving this? I am adding widgetAction & anotherWidgetAction to the ActionStack in indexAction, but how do I render them to placeholders in index.phtml? Any help appreciated with this, I've been playing with this on & off for a few weeks and am no closer to making it work! Thanks, Mark -- View this message in context: http://www.nabble.com/Zend_Layout-for-individual-actions--tp23356760p23356760.html Sent from the Zend Framework mailing list archive at Nabble.com.
