How to change $model->attributes value in controll

2019-02-18 11:44发布

UserMasterController Code:

public function actionUpdate($id){

    $model=$this->loadModel($id);

    if(isset($_POST['UserMaster'])){
        $model->attributes=$_POST['UserMaster'];
        $model->attributes['emailsent'] = 'N';

        if($model->save())
            $this->redirect(array('admin'));
    }

    $this->render('update',array(
        'model'=>$model,
    ));
}

the line which gives me an error is : $model->attributes['emailsent'] = 'N';

ERROR : Indirect modification of overloaded property UserMaster::$attributes has no effect

How can I change the attribute value ? I just want to set it as 'Y' or 'N' as per the condition

2条回答
该账号已被封号
2楼-- · 2019-02-18 11:54

Just try this $model->setAttribute($name,$value);

查看更多
你好瞎i
3楼-- · 2019-02-18 11:55

Use $model->emailsent='N';. Thats all

查看更多
登录 后发表回答