2010年2月22日星期一

[fw-mvc] Re: Passing parameters to view scripts

Hector Virgen wrote:
>
> When you call $this->render() from within a view script, the existing view
> is re-used. So you should be able to set it like this:
>
> // in view script
> <?php
> $this->showLogo = true;
> $this->render('header.phtml');
>
> // in header.phtml
> <?php if ($this->showLogo): ?>
>
> <?php endif; ?>
>
>

This would work indeed, but I think my solution is better because the added
parameter "showLogo" is persistent in your code. When you are going to
output another view script, your view will still contain "showLogo", and
that may potentially leads to problems, I think.

Hector Virgen wrote:
>
> However, I would suggest using Zend_Layout instead -- it's much better at
> handling layout-specific tasks and it contains it's own view instance,
> allowing you to set view vars like this:
>
> // in view script
> <?php
> $this->layout()->showLogo = true;
>
> // in layout
> <?php if ($this->layout()->showLogo): ?>
>
> <?php endif; ?>
>

I didn't know I could access the layout this way, good to know! But this
doesn't help in all situations, where a regular view script needs to include
another regular view script, having no relation with the global layout...

Thanks for the help!

--
View this message in context: http://n4.nabble.com/Passing-parameters-to-view-scripts-tp1565353p1565369.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: