Yii - dynamically change rules from controller

后端 未结 5 936
别那么骄傲
别那么骄傲 2021-02-09 11:15

Let\'s say I have a product which can have a colour. Depending on the product type, the colour field may or may not be required.

If colour is always required, I would ha

5条回答
  •  感情败类
    2021-02-09 12:05

    class LoginForm extends CFormModel
    {
        public $username;
        public $password;
    }
    
    $form = new LoginForm();
    $form->validatorList->add(
        CValidator::createValidator('required', $form, 'username, password')
    );
    

    Now $form has two required fields.

提交回复
热议问题