On Wed, 2005-01-12 at 18:15 -0500, Vsevolod (Simon) Ilyushchenko wrote:
> > It seems like the gist of your question is where to do the input
> > validation. The logical place to do it is in the model objects, but
> > this can be a pain unless you design them for it.
>
> I try to keep model object web-agnostic. So if there are any special
> rules about ignoring values of some web fields and changing others, I do
> it in controllers.
I wasn't suggesting that you would just pass the entire world to your
model objects. I meant that a controller would read the input and pass
the appropriate parameters to a model object. The model has no idea
that there's a web form involved.
> > Figuring out exactly
> > when the object is ready for the data to be validated is not all that
> > easy when you allow separate set() methods for individual properties,
> > and avoiding creating things in the database until it is validated can
> > also be messy. It basically means you have to structure your model
> > objects to accept all of their data in one call, or else have a standard
> > check before saving to the database. You also need a way for them to
> > tell you which part of the data was wrong.
>
> Yes, I always do an error check before a save action coming from the
> web. It happens in my BasicController, which is a parent class for
> various controllers.
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.
> > Although the model is the place that makes the most sense, handy tools
> > like Data::FormValidator are hard to resist for data validation, even
> > though the controller (or action, or whatever you want to call it) is
> > the wrong place for information about the data a model object needs.
>
> Right, but if I drop everything down to the model level, I would not be
> able to reuse the validators in different applications.
I'm not following this. Why would it be hard to share code between
model objects in different applications? You can use the same
techniques you would use for any other kind of code-sharing.
> > Maybe integrating this into Class::DBI would help. I see that
> > Class::DBI::FromForm is trying to do something like that.
>
> I actually had functionality similar to Class::DBI::FromForm from the
> start, I would even say it's been a key feature.
It doesn't sound like your approach is the same, since FromForm appears
to do the validation in the model, not in the controller.
Class::DBI::FromCGI is what Maypole uses at the moment. It does very
basic validation, but nothing like Data::FormValidator.
- Perrin
_______________________________________________
maypole mailing list
maypole at lists.netthink.co.uk
http://lists.netthink.co.uk/listinfo/maypole
This archive was generated by hypermail 2.1.3 : Thu Feb 24 2005 - 22:25:57 GMT