yii-components

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

久未见 提交于 2019-12-01 06:34:23
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 Use $model->emailsent='N

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

喜你入骨 提交于 2019-12-01 04:58:18
问题 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

Yii add filter to a virtual attribute in CGridView and make it sortable

戏子无情 提交于 2019-11-29 13:27:39
问题 I have the following Models : User with columns {id,user_name,password,user_type} Admin with columns {id,user_id,full_name,.....etc} Editor with columns {id, user_id,full_name,...etc} and the relations are User : 'admin' => array(self::HAS_ONE, 'Admin', 'user_id'),'editor' => array(self::HAS_ONE, 'Editor', 'user_id'), Admin : 'user' => array(self::BELONGS_TO, 'User', 'user_id'), Editor : 'user' => array(self::BELONGS_TO, 'User', 'user_id'), Now i had setup a virtual attribute fullName in User

How to validate email and email already exist or not check, in Yii Framework?

和自甴很熟 提交于 2019-11-29 09:14:51
How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii. You can set your model validations as below public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( //First parameter is your field name of table which has email value array('email', 'email','message'=>"The email isn't correct"), array('email', 'unique','message'=>'Email already exists!'), ); } Yii Reference Link For More Detail: http://www.yiiframework.com/wiki/56/