disable field on rules model yii

2019-08-23 01:56发布

i am trying to disable a field on update rules models but i am having error.

i try like:

array('date', 'constraint', 'readOnly'=>true, 'on'=>'update'),

but i am having this error:

"include(constraint.php): failed to open stream: No such file or directory"

I can disable from view using htmloptions but i need do it from model because on update i need to disable more than 5 fields.

how could i do this?

thx in advance

标签: yii
1条回答
时光不老,我们不散
2楼-- · 2019-08-23 02:12

You are declaring a rule with a validator that doesn't exist, so it's normal that you have an error:

array('date', 'constraint', 'readOnly'=>true, 'on'=>'update'),

This line is doing the following: apply the validator constraint on the date field on update scenario with param readOnly set to true.

The validator constraint doesn't exists has a built in functonnality in Yii so if you havn't created it then it doesn't exist!

Documentation:

Edit: In your form you could do something like:

<?php 
    echo $form->textField(
        $model,
        'email',
        array('readonly'=>($model->scenario == 'update')? true : false)
    );
?>

As you can see the readonly value will depend on the scenario.

查看更多
登录 后发表回答