Is using Zend_Form too much mixing of presentation with business logic?
Isn't MVC supposed to separate the presentational code from everything else? Wouldn't this make it much more difficult for front end design开发者_C百科ers to work on code separately?
Here is what Matthew Weier O'Phinney of ZF had to say on using Zend Form in your Model
Some argue that this violates the concept of "separation of concerns", due to the fact that it mixes rendering logic into the model. I feel this is a pedantic argument. When attached to a form, Zend_Form can be used strictly as an input filter; you would pull the form from the model when you wish to render it, and perform any view-specific actions -- configuring decorators, setting the action and method, etc -- within your view script. Additionally, the various plugins -- validators, filters, decorators -- are not loaded until they are used -- meaning there is little to no overhead from the decorators when you merely use Zend_Form as an input filter.
Basically, this approach helps you adhere to the DRY principle (one validation/filter chain), while simultaneously helping you keep a solid separation of business and view logic. Finally, you gain one or more form representations of your model, which helps with rapid application development, as well as providing a solid, semantic tie between the model and the view.
Of course, if you argue that front designers have to look into the individual form renderers or even the individual Zend Form configurations whenever they want to tweak the output, you are right: this is more difficult than just typing some HTML directly. And the fact that Zend_Form isn't exactly developer friendly to begin with doesnt make it any better.
<my2c mood="rantish">
After having heard a multitude of things that frontend designers are incapable of nowadays, I wonder if they should author HTML at all. With CSS Selectors and XPath in Javascript, there is nothing on a page a front end developer could not tweak, so why bother about the HTML.
</my2c>
In my opinion, forms is a very special part of HTML page, much closer to the business logic.
It's okay to use form-builder (and it's extremely tempting - to designate a field just once, not ten times for the form value, error handler, form validator and so on).
So, I see nothing bad in this particular case.
You can render Zend_Form decorators individually to make use of Zend_Form simpler for front end designers: http://weierophinney.net/matthew/archives/215-Rendering-Zend_Form-decorators-individually.html
Anyway, you can't use only HTML because you need to load the values, add the errors...
精彩评论