Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 533
Darshit Gajjar Avatar asked Dec 04 '22 03:12

Darshit Gajjar


2 Answers

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

like image 68
dInGd0nG Avatar answered Feb 25 '23 11:02

dInGd0nG


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

like image 45
hackil Avatar answered Feb 25 '23 11:02

hackil