我需要停止更新某些值,即使這些值設置爲POST數組。要做到這一點我在yii規則中使用不安全。更新時,跳過某些屬性更新yii
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
$模型 - >屬性= $ _POST [ '用戶'];
我需要保存時跳過某些屬性。
$ model-> save();
你可以添加你的更新功能嗎? – secretlm
@secretlm它不是一個函數。它的一個場景。 – dev1234
「我需要停止更新某些值,即使那些設置爲POST數組」=>我想查看您在「更新」操作中爲模型屬性設置值的代碼。 – secretlm