I've gone ahead and added validation to our test project: http://code.google.com/p/plushcode/source/browse/#svn/trunk/ZendModel/application/default/models
If you take a look at the indexController you'll now see I've added an updateAction that uses a Zend Form component.

The goal of the validation was to provide context sensitive validation on a model. A model by itself might not know if it's valid or not so you'll want to apply different contexts depending on what the client operation is. Saving an order might have a different validation need than shipping an order. Instead of hacking a bunch of if/else statements you can simple say


$order->setValidator(new order_validation_NewOrder());

// OR

$order->setValidator(new order_validation_ShipOrder());

if(!$order->isValid()) {
$messages = $order->getMessages();
}



and $order->isValid() will operate on that context object. The form object get's pass a validator so it can also operate on the same validator chains as the model so you don't have to duplicate that logic.

Anyway, I think it can be improved so take a look!
If you've downloaded and installed the code you'll be able to find the example on your local machine: http://youraddress/index/update

Ready for More?

Follow Me @jimplush