Cvalidator

[size="2"]I tried to write a feature class of model validation class.

Rahnayy according to the following link:

create-your-own-validation-rule

with this code:




class jDateValidate extends CValidator

{


   public $jdate;

   public $gdate;




  private $jPattern ="#^\d{2}([^\d]*)\d{2}([^\d]*)\d{4}$#is";


   protected function jvalidate($object, $attribute)

   {

      $value = $object->$attribute;


      if( ! preg_match($this->jPattern, $value))

      {

        $this->addError($object, $attribute, "Invalid date! The correct date format is like '2001-01-09'. Please try again.");

      }


   }




 }




But faced with the following error when I go:

problem was fixed for the override function ValidateAttribute:[/size]




class jDateValidate extends CValidator

{


   public $jdate;

   public $gdate;




   private $jPattern ="#^\d{2}([^\d]*)\d{2}([^\d]*)\d{4}$#is";


   protected function validateAttributes($object, $attribute)

   {

      $value = $object->$attribute;


      if( ! preg_match($this->jPattern, $value))

      {

        $this->addError($object, $attribute, "Invalid date! The correct date format is like '2001-01-09'. Please try again.");

      }


   }




 }



Yes, my mistake was that instead of override the ValidateAttribute function. I wrote a function with a different name. If the need for validation by the class convention to override the abstract functions in the CValidator class.