When i add a rule in the model, the planned message appears well
array('studCount', 'numerical','max'=>25, 'tooBig' => "{attribute} est supérieur à 25: choisissez un autre cours ou adressez-vous à l'administrateur")
But, as i want the rule only play in some conditions, i change the way to do that using a function.
So, in the rules, i write:
array('studCount', 'verifPlaces')
and i add the function
public function verifPlaces($attribute, $params)
{
// 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 <> $this->class_id_old))
{
$class = Classes::model()->findByPk($this->class_id);
$this->studCount = $class->studCount;
// ajout d'une règle
$ev = CNumberValidator::createValidator('numerical', $this, 'studCount', array('max'=>25),
array('tooBig' => "{attribute} est supérieur à 25: choisissez un autre cours ou adressez-vous à l'administrateur"));
$ev->validate($this);
}
}
The control is done, but that way the message is not mine, but the generic of yii’s tooBig (in french): “Nombre d’étudiants du cours est trop grand (maximum : 25).”, instead of my message.
Am i badly declare the validator?
Thanks for your advices