Yii - dynamically change rules from controller

后端 未结 5 843
太阳男子
太阳男子 2021-02-09 11:08

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 11:49

    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.

提交回复
热议问题