Improved Plugin for Model Validation: sfPropelValidatePlugin

I 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
  1. Thierry Schellenbach’s avatar

    In fact I didn’t look at builders yet. Could you post a tutorial?

  2. Lucas’s avatar

    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