Re: [Maypole] Multiple controllers

From: Vsevolod (Simon) Ilyushchenko (simonf at cshl.edu)
Date: Wed Jan 12 2005 - 23:15:37 GMT


Perrin Harkins wrote:
> On Wed, 2005-01-12 at 17:14 -0500, Vsevolod (Simon) Ilyushchenko wrote:
>
>>I was just wondering if anyone has created some kind of formal pattern
>>to deal with this. On a page that has several controllers, this can get
>>messy - you have to send data from the model (and maybe from the web) to
>>the controller, invoke the error checking function and then transfer
>>possibly modified data back to the model.
>
>
> 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.

> 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.

> 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.

> 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.

Simon

-- 

Simon (Vsevolod ILyushchenko) simonf at cshl.edu http://www.simonf.com

Terrorism is a tactic and so to declare war on terrorism is equivalent to Roosevelt's declaring war on blitzkrieg.

Zbigniew Brzezinski, U.S. national security advisor, 1977-81

_______________________________________________ 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