2008年11月4日星期二

Re: [fw-mvc] Nested Partials

-- Dan Wilson <dan@acucore.com> wrote
(on Tuesday, 04 November 2008, 01:48 PM -0700):
> On Tue, Nov 4, 2008 at 1:45 PM, Matthew Weier O'Phinney
> <matthew@zend.com> wrote:
> > Nested partials work, but I'd recommend against them. partial() clones
> > the view object... and all helpers... and all filters... It's a bit
> > resource intensive, though relatively performant. I recently tested this
> > (nested partials) as I was investigating ways to make partial() more
> > performant (though I ultimately did not come up with anything), so I
> > know it works.
>
> So what do you suggest? Should I just have everything in a large
> partial? That's a little frustrating because it could become quite
> large.

It depends on how you're using partials. I see a lot of people doing the
following:

<?= $this->partial('foo.phtml') ?>

What's wrong with the above? The two primary features of partial() are
to provide the ability to render view scripts from another module, and
to provide a protected variable scope. If you're not doing either of
these things, then there's no reason to use it over render() -- in fact,
it's *better* to use render() in such a case, as it will be faster.

Reasons to use partials?

* You need to render a view script in a particular module, and don't
want that module's view script path at the top of the stack when
done
* You're actually passing variables to the partial

The same rules apply to nested partials -- if the nested partial is not
using a different module or being passed variables, use render()
instead.

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

没有评论: