Oh, for those who doesn't know what to do with the code. Save it as sfPropelRecordExistsValidator.class.php and place it in your project lib directory then symfony cc.
On Tue, Apr 21, 2009 at 3:26 PM, Sid Bachtiar <[email protected]> wrote: > I wrote a simple one just now ... in case someone else need it, here it is > > class sfPropelRecordExistsValidator extends sfValidator > { > public function execute (&$value, &$error) > { > $class = $this->getParameter('class'); > $column = $this->getParameter('column'); > > $class_peer = $class.'Peer'; > $table_name = constant($class_peer.'::TABLE_NAME'); > > $c = new Criteria(); > $c->add($table_name.'.'.$column, $value); > $result = call_user_func(array($class_peer, 'doSelect'), $c); > if ($result) > { > return true; > } > else > { > $error = $this->getParameter('error_msg'); > return false; > } > } > > public function initialize ($context, $parameters = null) > { > // Initialize parent > parent::initialize($context); > > // Set default parameters value > $this->setParameter('column', 'ID'); > > // Set parameters > $this->getParameterHolder()->add($parameters); > > return true; > } > } > > To use it in validation yml file: > > age_bracket_id: > required: > msg: Required > sfPropelRecordExistsValidator: > class: AgeBracket > column: ID > error_msg: Required, please select one > > > > On Tue, Apr 21, 2009 at 3:20 PM, Eno <[email protected]> wrote: >> >> On Tue, 21 Apr 2009, Sid Bachtiar wrote: >> >>> Can't seems to find a validator for Symfony 1.0 for checking if an ID >>> exists in a table. Anyone knows if that exists in Symfony 1.0? A >>> plugin or something? >> >> Last time I had a similar need, I wrote my own validator, but I would love >> to know if there's another way. >> >> >> -- >> >> >> >> >> >> > > > > -- > Blue Horn Ltd - System Development > http://bluehorn.co.nz > -- Blue Horn Ltd - System Development http://bluehorn.co.nz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
