【发布时间】:2013-12-05 12:32:01
【问题描述】:
我需要停止更新某些值,即使这些值设置为 POST 数组。为此,我在 yii 规则中使用了 unsafe。
array('id', 'unsafe', 'on'=>'update'),
仍然如此,我无法跳过更新的 id。
如何用 yii 做到这一点?
下面是我的规则函数..
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, body, created_date', 'required'),
array('name', 'length', 'max'=>128),
array('body', 'length', 'max'=>512),
array('id', 'unsafe', 'on'=>'update'),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, name, body, created_date', 'safe', 'on'=>'search'),
);
}
更新 1
$model->属性 = $_POST['User'];
我需要在保存时跳过某些属性。
$model->save();
【问题讨论】:
-
可以添加更新功能吗?
-
@secretlm 它不是一个函数。这是一个场景。
-
“我需要停止更新某些值,即使这些值设置为 POST 数组” => 我想查看您在“更新”操作中为模型属性设置值的代码。
-
@secretlm 请检查更新的问题