[Maypole] Multiple controllers

Perrin Harkins perrin@elem.com
Thu, 13 Jan 2005 09:44:06 -0500


Vsevolod (Simon) Ilyushchenko wrote:
>> I'm talking about doing validation in the model objects here, so your
>> controller would have to call a validation method on the model objects
>> rather than implement its own.
> 
> 
> Right, but since my controllers hold references to, say, date checkers, 
> they first call errorCheck() on the date checkers and then on the model.

The trouble with that is that now your controller knows something about 
what format of data you want, which is really the model's domain.

> I may choose to show date as one text field, or as three numerical 
> fields. Depending on this, I will initialize my date checker objects 
> differently to use different validation rules. So the object 
> initializing the date checkers should know something about the 
> presentation, and I decided to let controllers rather then models to 
> initialize (and store) the checkers.

To keep the information about your data in the model and out of the 
controller, you could normalize (but not validate!) your date input in 
your controller before passing it to your model, and let your model 
validate it, or make your model accept multiple formats.  It gets 
tricky, because you might want to normalize the data by turning it into 
a DateTime object, but that will fail if the data is bad.  To get around 
that, you might have to use a standard text format instead, so that the 
model can do the validation.

It sounds like what you are currently doing is more along the lines of 
the compromise I mentioned -- using something like Data::FormValidator 
in the controller, even though it kind of breaks MVC, because it's so 
much easier.  I do this too, but would like to have better separation.

- Perrin


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.11 - Release Date: 1/12/2005