Warning instead of error on model validation

Hi,

My model has an attribute whose validation rule needs to throw an error or a warning depending on the value of another attribute (say ‘is_enforced’). So, if is_enforced is set to false, the particular validation on the attribute should display a warning message in the form but validation should not fail (ie, validate() should return true). If is_enforced is set to true, validation will behave normally. Would I have to change the error-related values and settings of my model and the attribute in question in order to accomplish this? Or is it better to extend CModel and add functionality for warnings similar to errors?

Thanks.

Hi,

in similar subject, i’ve done a rule caling a function.

In rules:




...

array('studCount', 'verifPlaces'),

...



And the function called:




public function verifPlaces($attribute, $params)

{

   // on vérifie si l'étudiant était déjà rattaché à ce cours 

   if(!$relStudentClass = RelStudentClass::model()->exists('student_id = '.$this->student_id . ' and class_id = ' .$this->class_id))

   {

      // les moniteurs ne peuvent pas mettre plus de 25 étudiants dans un cours (par _form2 de student), cette action est réservée à l'administrateur ou au super moniteur

      if ( Yii::app()->user->isMoniteur() && $this->class_id > 0)

      {

         $class = Classes::model()->findByPk($this->class_id);

         $this->studCount = $class->studCount + 1; // on ajoute 1 puisqu'on veut ajouter un étudiant dans le cours

         // ajout d'une règle

         $ev = CNumberValidator::createValidator('numerical', $this, 'studCount', array('max'=>25, 'tooBig' => "{attribute} est supérieur à 25: choisissez un autre cours ou adressez-vous à l'administrateur"));

         $ev->validate($this); 

      }

      // pour les autres (non moniteurs), on doit afficher un message d'avertissement

      elseif($this->class_id > 0)

      {

         Yii::app()->user->setFlash('notice','Il y aura plus de 25 étudiants dans ce cours');

      }

   }

}



In a case, a rule is applied, with error if not checked, and in the other case, a notice message is shown.