In this example create a function checkStatus() and apply in the rules like below:
If the status is false then it will display the error message.
Yii2 custom validation rules
//model file
public function rules()
{
return [
[['status'], 'checkStatus'],
// other rules
];
}
public function checkStatus($attribute, $params)
{
if($this->status == false){
$this->addError($attribute, 'Status cannot be false');
}
}
No comments:
Post a Comment