Yii2: Conditional Validator always returns required

前端 未结 5 1480
-上瘾入骨i
-上瘾入骨i 2021-02-07 17:24

I am trying to use Yii2\'s conditional validator as given in the guide like:

Model code

public function rules()
{
   // $discharged = function($model) {          


        
5条回答
  •  囚心锁ツ
    2021-02-07 17:39

    ['package_id_fk', 'required', 'when' => function($model) {return $model->type == 'PACKAGE';}, 'enableClientValidation' => false],
    

    It works for me.

提交回复
热议问题