Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Why I dislike the MVC implementations in Webby siracusa (Friar) |
on Jun 08, 2005 at 02:01 UTC ( [id://464525]=note: print w/replies, xml ) | Need Help?? |
The big difference is that one important responsability is taken from the view and delegated to the controller, which is processing the user input. For instance, in MVC2, if you have a datetime field splitted in two inputs, the View AND the Controller should know about that, because the View will split the datetime into the appropriate fields, and the Controller would put it back before sending to the model. Not the way I do it, although I'm not sure what I'm doing is any more "pure" MVC. It's just what works for me. Anyway, I modularize my forms and fields so that neither the view or the controller have to worry about stuff like this. The form object simply says "I have a split MDY date field called 'start_date.'" The application associates the form with a page:
Asking the app to show the page will init the form and pass it to the page.
From with the page, it's trivial (but templating-language-specific) to print the "start_date" field as XHTML (Mason example):
Nowhere does anyone have to be aware that "start_date" is a split field--not even in the query parameters. These would both work transparently:
Ditto for setting fields directly:
And so on. My webapp passes query params down to the form object as a hash. No heroics necessary. The form object can init its fields based on that hash, doing any necessary subfield initialization. Form objects can also be initialized with model objects: $edit_form->init_with_product($product)Individual fields can be set with objects when appropriate (e.g., DateTime objects) from within the controller (or the view if it's embedded-perl-ish like Mason). Finally, my views just call methods on field objects to produce the appropriate HTML. Abstracting forms (and by extension, fields) is a big, big win for webapps IME. It lets each piece of "MVC" act as is appropriate to itself without sweating "external" details.
In Section
Meditations
|
|