YII CGRIDVIEW, Add form actions to cgridview

This is a tutorial for how to add input text-Field, check-box, buttons in CGridView. Scenario  This is CRUD pages for admin menu management. So, Menu model have following things: menuId : INT menuName : VARCHAR sortOrder : INT (Admin may change menu order, based on that front side menu will render) isActive : BOOL (only values with… Continue reading YII CGRIDVIEW, Add form actions to cgridview

YII Client side form validation error doesn’t prevent form submit

YII Client side form validation error doesn’t prevent form submit To get this behavior you just need to add ‘clientOptions’ => array(‘validateOnSubmit’=>true), to your configuration so it would look like this: $form=$this->beginWidget( ‘CActiveForm’, array( ‘id’=>’member-form’, ‘enableAjaxValidation’=>false, ‘enableClientValidation’=>true, ‘clientOptions’ => array(‘validateOnSubmit’=>true), ));

YII cgridview Tricks

Yii cgridview make custom drop down filters, Yii cgridview set row color based on a condition, Yii cgridview add time picker in filter, Yii cgridview add drop down in colum values Here is an example how you can make custom drop down filters in YII cgridview: $this->widget(‘zii.widgets.grid.CGridView’, array( ‘id’ => ‘card-applications-grid’, ‘dataProvider’ => $model->search(), ‘filter’ =>… Continue reading YII cgridview Tricks

PHP YII Change the Row Color Based on the Column value in CGridView [rowCssClassExpression]

Belows is how you can use CGridView ‘rowCssClassExpression’ to change row color based on a column’s value: $this->widget(‘zii.widgets.grid.CGridView’, array( ‘dataProvider’=>$dataProvider, ‘rowCssClassExpression’=>'($data->column_name==0)?”new”:”old”‘, ‘columns’=>array( … ),)); You can also call a custom php function, and pass the $data variable to it. That function should return the class name for the given row 🙂

yii change sorting sort order by drag drop Creating a jQueryUI Sortable CGridView Yii Framework

The article below is copied from this URL http://www.yiiframework.com/wiki/238/creating-a-jqueryui-sortable-cgridview/ . That linked article has a small error which i have removed here: —————————————————————————————- I have had to do this a couple of times now so I figured I would share it with the community. I am going to keep this short because I really hope that you… Continue reading yii change sorting sort order by drag drop Creating a jQueryUI Sortable CGridView Yii Framework

Yii redirect method

{Redirect to HomePage} $this->redirect(Yii::app()->homeUrl); {Redirect to Module ‘Admin’} $this->redirect(array(‘/Admin’)); {Redirect to Contorller/Action} $this->redirect(array(‘post/view’));

Yii, update record (update query) method

Update By Primary KeyModel::model()->updateByPk($Model->id,array(“status”=>’ok’)); Update All RowsModel::model()->updateAll(array(‘user’=>”$userid”,’date’=>$currenttime),”status=>’ok'”);

Yii, how to add current date or time or timestamp in DB field automatically

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’) );}?>

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