Improved Plugin for Model Validation: sfPropelValidatePlugin
Sun 9 Sep 2007 by Rob RosenbaumI have updated my plugin for doing model-based validation in symfony. The new plugin uses the Propel builders instead of behaviors, so it is now called sfPropelValidatePlugin instead of the former (unwieldy) name sfPropelValidateBehaviorPlugin. If you have not investigated the Propel builder classes, I suggest you give them a look. By overriding the default classes used to build your Propel object and peer classes, you can write your modifications directly into your model's base classes. This is a much cleaner and more readable solution than using Propel behaviors, and you avoid the performance hit that behaviors incur.
The default Propel builders can be found in the symfony source in these places:
symfony/addon/propel/builder/sfObjectBuilder.php symfony/addon/propel/builder/sfPeerBuilder.php
The classes these inherit from are buried. They can be found here:
symfony/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ComplexObjectBuilder.php symfony/vendor/propel-generator/classes/propel/engine/builder/om/php5/PHP5ComplexPeerBuilder.php
5 Comments Add your own
1. Thierry Schellenbach | September 11th, 2007 at 7:32 am
In fact I didn't look at builders yet. Could you post a tutorial?
2. rpsblog.com » A wee&hellip | September 16th, 2007 at 6:52 pm
[…] Improved Plugin for Model Validation: sfPropelValidatePlugin […]
3. Lucas | October 19th, 2007 at 10:06 am
Hi Nice plugin, i just made some modifications.
Using:
if (!$article->save()) {
$this->forward('patient', 'edit');
}
sometimes does not returns true even if the validations succed, if you model has not been modified for ex, your post will always been forwarded.
The solution i found was adding the following to sfValidateObjBuilder.php:
$updated = '
if(!$this->isModified()) return true;
';
$tmp = preg_replace('/(:save:pre.*?}.*?})/s', '\1'.$updated, $tmp, 1);
Cheers L
4. Lucas | March 18th, 2008 at 1:06 pm
PS: the modification will only work if propel behaviours is enabled at propel.ini
5. pdaether | April 3rd, 2008 at 10:43 am
Great Plugin!
But is it possible to set the Propel builders only for specific models - for example in the schema files?
Or is the behavior version still available?
I had to add model-based validation only for a couple of models.
Thanks!
Patrick
Leave a Comment
Please: No emoticons or excessive punctuation.Trackback this post | Subscribe to the comments via RSS Feed