在模型规则中,我有自定义规则:
array('source_id, postcode, state, fname, lname, email, address, city, birthday, gender, ip, phone,validation', 'validateCustom', 'on'=>'spam,normal'),
问题是,此规则执行12次(属性数量为-1)。
public function validateCustom()
{
//here all validations done
}
如何预防?我想验证所有这些参数1次而不是x。谢谢你的帮助。
答案 0 :(得分:1)
我有个主意:
class YourModel extends ActiveRecord
{
public $ranValidate = false;
.......
public function validateCustom($attribute, $params)
{
if($this->ranValidate == false) {
//Implement your code
$this->ranValidate = true;
}
}
}