How to change $model->attributes value in controller - Yii

Darshit Gajjar picture Darshit Gajjar · May 9, 2012 · Viewed 14.6k times · Source

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

Answer

dInGd0nG picture dInGd0nG · May 9, 2012

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