禁用规则模型 yii 上的字段 [英] disable field on rules model yii

查看:25
本文介绍了禁用规则模型 yii 上的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试禁用更新规则模型上的字段,但出现错误.

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

我尝试:

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

但是我遇到了这个错误:

but i am having this error:

include(constraint.php): 无法打开流:没有那个文件或目录"

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

我可以使用 htmloptions 从视图中禁用,但我需要从模型中禁用,因为在更新时我需要禁用 5 个以上的字段.

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.

我怎么能这样做?

提前谢谢

推荐答案

您使用不存在的验证器声明规则,因此出现错误是正常的:

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'),

这一行正在执行以下操作:在 update 场景中的 date 字段上应用验证器 constraint,参数为 readOnly 设置为 true.

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

验证器 constraint 不存在,在 Yii 中有一个内置的功能,所以如果你没有创建它,那么它就不存在!

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!

文档:

在您的表单中,您可以执行以下操作:

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.

这篇关于禁用规则模型 yii 上的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆