2009年7月10日星期五

Re: [fw-mvc] Static view helpers

-- Exception e <exceptione@hotmail.com> wrote
(on Friday, 10 July 2009, 07:52 AM -0700):
> I have a class with a few methods that performs extraction and
> formatting of a given piece of xml. This is to be used in a View.
> Since this class is stateless, I thought it would be a good idea to
> make it a static class. However, this doesn't fit the current
> architecture of ZF. I would like to hear your thoughts on this
> problem.

Just because a class is stateless doesn't mean you should necessarily
make it static. If you need later to make it stateful, the static
members will get in your way; if you later need to extend it, static
members can often make extension difficult.

Since Zend_View allows you to simply access the helper directly, just
create a regular helper. You can always instantiate it without Zend_View
and utilize it.

> 1) Should I access a static view helper directly?
>
> static class NameSpace_View_Helper_Format {…}
>
> in the View:
> echo NameSpace_View_Helper_Format::formatX($xml);
>
> 2) or should I access a unprefixed static class directly:
>
> static class NameSpace_Format {…}
>
> in the View:
> echo NameSpace_Format::formatX($xml);
>
> 3) …?

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

没有评论: