2008年11月26日星期三

Re: [fw-mvc] Named response segments in view scripts

>Um... no. render() with a null first argument only renders the current
>action as found in the request. There is no way currently to render
>*all* actions at once.

Well I wasn't trying to render them all at once...I have action stack which I assumed would call this init() function for every action request, in which case null would be the current request (of which there is only one). I was just looking for a generic way to have all the actions in this controller render to a specific segment without having to manually put that in each action. Would $this->_helper->viewRender->setResponseSegment() do the trick?

>When you call render() manually, it renders immediately... and then
>tells the ViewRenderer not to do any auto rendering. This is to prevent
>double-rendering. So, calling render() from init() is a bit self
>defeating -- because then your normal view script won't render during
>normal execution..

Makes sense...however I do recall that the action was correctly in the layout script.

With this in mind, I moved the $this->render() code to the individual actions and out of the init() function. Unfortunately, I still must be missing something because its not doing much.

On Wed, Nov 26, 2008 at 3:25 PM, Matthew Weier O'Phinney <matthew@zend.com> wrote:
-- Abraham Block <atblock@gmail.com> wrote
(on Wednesday, 26 November 2008, 03:10 PM -0500):
> Sounds plausible, if not a little ugly...but I can't get it to work for some
> odd reason...
>
> I have an "EventsController" with an action "list"...at the end of the action,
> I have an actionstack with different actions from the "SideboxController"...
>
> SideBox controller has an init() function  which looks like this:
> public function init() {
>         $this->render(null, 'sideboxes');
> }
>
> Which I was hoping would output all actions from this controller into the
> sideboxes segment.

Um... no. render() with a null first argument only renders the current
action as found in the request. There is no way currently to render
*all* actions at once.

> It seemed to work in my layout script, but in the view script (events/
> list.phtml) I have <?=Zend_Controller_Front::getInstance()->getResponse()->
> getBody('sideboxes');?>
>
> ...which doesn't display anything!

When you call render() manually, it renders immediately... and then
tells the ViewRenderer not to do any auto rendering. This is to prevent
double-rendering. So, calling render() from init() is a bit self
defeating -- because then your normal view script won't render during
normal execution..

> On Wed, Nov 26, 2008 at 10:57 AM, Matthew Weier O'Phinney <matthew@zend.com>
> wrote:
>
>     -- Avi Block <atblock@gmail.com> wrote
>     (on Wednesday, 26 November 2008, 07:40 AM -0800):
>     >
>     > How do I access a named response segment in a view script which is not my
>     > layout script?
>     > I have a couple of pages within my layout that have a sidebar themselves,
>     > and i'm trying to render to that sidebar using an actionstack.
>
>     Grab it from the response object:
>
>        $response = Zend_Controller_Front::getInstance()->getResponse();
>        $content  = $response->getBody($segmentName);
>
>     > Alternatively, I would like to do this via a "sublayout"...but I can't
>     > figure out how to render a layout within another layout.
>
>     --
>     Matthew Weier O'Phinney
>     Software Architect       | matthew@zend.com
>     Zend Framework           | http://framework.zend.com/
>
>
>

--
Matthew Weier O'Phinney
Software Architect       | matthew@zend.com
Zend Framework           | http://framework.zend.com/


没有评论: