A PHP callable whose return value determines whether this validator should be applied. The signature of the callable should be function ($model, $attribute), where $model and $attribute refer to the model and the attribute currently being validated. The callable should return a boolean value.
This property is mainly provided to support conditional validation on the server-side. If this property is not set, this validator will be always applied on the server-side.
public $subModel;
public function init()
{
parent::init();
$this->subModel = new SubModel();
}
public function afterValidate()
{
parent::afterValidate();
$this->subModel->validate();
}
public function load($data, $formName=null) {
$this->subModel->load($data);
return parent::load($data, $formName);
}
public function afterSave($insert, $changedAttributes) {
parent::afterSave($insert, $changedAttributes);
$this->subModel->save(false);
}
'when' => function($model){
reeturn $model->subModel->property == 1;
}