To add current date or time or timestamp in DB field automatically Using Rules in model use it like below : <?php/** * @return array validation rules for model attributes. */public function rules(){ return array( array(‘title’,’length’,’max’=>255), array(‘title, created, modified’, ‘required’), array(‘modified’,’default’, ‘value’=>new CDbExpression(‘NOW()’), ‘setOnEmpty’=>false,’on’=>’update’), array(‘created,modified’,’default’, ‘value’=>new CDbExpression(‘NOW()’), ‘setOnEmpty’=>false,’on’=>’insert’) );}?>
Month: February 2012
YII, How to get current controller name and action name
To get current controller name use this code : <?php$controllerId = Yii::app()->controller->id;//or$controllerId = $this->getId();?> To get current action name/id being executed, if you are inside beforeAction() or afterAction(), use the received CAction argument <?php//inside beforeAction or afterActionpublic function beforeAction($action){ $actionId = $action->id;…?> or just elsewhere inside your controller <?php$actionId = $this->getAction()->getId();?> To get name of… Continue reading YII, How to get current controller name and action name
Yii, return to previous url after login or logout
If you want to return to your previous url after login or logout try this : <?php$this->redirect(Yii::app()->request->urlReferrer);?> To set the return url to be the url that was before the login page or registeration page was called you can put following code in views/layouts/main.php file : <?php//this checks id the controller action is not ‘login’… Continue reading Yii, return to previous url after login or logout