<?php
class Kaf_Model_Rule_Uuid extends Kaf_Model_Data{
public
$uuid;
public function rules(){
return array(
array(
'uuid',
'Kaf_Validator_Member', 'callback' => 'validateUuid',
'uuid' => $this->uuid,
'message' => '{attribute}Invalid'
),
);
}
}
Basically, I have defined some rules which will take model attributes as it’s params, But attributes is unassigned untill I use $model->attrubites = …, So after that step, I intend to set $_validators to null to force a recompiliation of the rules before validate() called, This time, ‘uuid’ => $this->uuid, will be assigned.
Since _validators is read only to me, I came up with a workaround to reset the validators:
public function setAttributes($values, $safeOnly=true){
parent::setAttributes($values, $safeOnly);
$validatorList = $this->getValidatorList();
$validatorList->clear();
$validatorList->mergeWith($this->createValidators());
}