I think I see your point, pretty much. I suppose that sort of extra
validation logic should be in the controller, by process of elimination.
Since the model's not supposed to known anything about things like $_POST
vars... right?

On 9/5/07, Justin Hendrickson <[EMAIL PROTECTED]> wrote:
>
> This approach is perfectly fine, however, it will only validate the
> object in question.
>
> A good example of a shortfall of this approach would be confirming
> that two password fields match. Technically, you're going to want to
> validate more than just the model data, so you'll need an input filter
> for any forms as well.
>
> Then again, depending on your exact needs, validating both might be
> overkill.
>
> On 9/5/07, David Mintz <[EMAIL PROTECTED]> wrote:
> >
> > Here's what I plan to do, and I'd love some feedback as to whether it's
> > considered good practice.
> >
> > class MyModel  extends Zend_Db_Table_Abstract {
> >
> >    /* $_dependentTables & $_referenceMap defined here */
> >
> >   protected $validationErrors;
> >
> >
> >    public function validate() {
> >
> >          // all the Zend_* validation setup here
> >
> >         $input = new
> > Zend_Filter_Input($filters,$validators,$data);
> >
> >
> >         $this->validationErrors = $input->getMessages();
> >
> >         return $Input->isValid();
> >
> >         }
> >    }
> >
> >    public function getValidationErrors() {
> >       return $this->validationErrors;
> >    }
> > }
> >
> > So, in the corresponding controller...
> >
> > if ($model->validate()) {
> >
> >    //  save the data to db, or whatever, etc
> >
> > } else {
> >
> >     // put $model->getValidationErrors() in the view
> >
> > }
> >
> > but I am also thinking validate(), after (maybe) populating its
> > errorMessages field, could return $this so that a controller could say
> >
> > if ($errors = $model->validate()->getValidationErrors()) {
> >         // ...
> > }
> >
> > ... but i guess then you'd *have* to do something like that if
> validate()
> > doesn't return a boolean. (duh).
> >
> > Thoughts?
> >
> > This noob appreciates your help.
> >
> > --
> > David Mintz
> > http://davidmintz.org/
> >
> >  The subtle source is clear and bright
> > The tributary streams flow through the darkness
>



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness

Reply via email to