-- lightflowmark <[email protected]> wrote
(on Wednesday, 15 April 2009, 01:18 AM -0700):
> I'm having a conceptual difficulty with view helpers & decorators and was
> hoping someone could clarify this for me:
> 
> When a form element (e.g. a text input) is rendered, the work of creating
> the form element markup (i.e. <INPUT TYPE=text ...>) is done by the
> 'ViewHelper' decorator, which calls a view helper set by the element itself
> (in this case, the FormText view helper).
> 
> Why functionality to create the markup in a view helper, rather than have a
> 'FormText' decorator which returns the form element markup directly?  Why is
> the decorator acting as a wrapper for the view helper?
> 
> Any insight appreciated, I'm trying to do something very similar and would
> like to understand the reasoning behind this design.

I chose to do the markup using view helpers to prevent code duplication,
plain and simple. For almost every element, we already had view helpers
created that could generate the markup. The logic is non-trivial -- it
ensures that attribute names and values are properly escaped, that the
necessary attributes are present, and more. Duplicating this directly in
the decorators made no sense (and still doesn't) -- so the "ViewHelper"
decorator was created. It simply takes metadata from the element and
passes it to the appropriate view helper, and then returns the content.

Again, the point is that the view helpers existed *first*. Even if they
had not, it's entirely possible that users would want to create form
input in view scripts without needing to use Zend_Form -- which would
have led to the creation of view helpers sooner or later.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to