Skip to main content

Posts

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' => $model, 'afterAjaxUpdate' => 'reinstallDatePicker', 'rowCssClassExpression'=>'($data->is_updated==1)?"application_updated":"application_not_updated"', 'columns' => array( array( 'name'=>'applicant_id', 'value'=>'$data->applicant_id', 'filter'=> CHtml::listData($model->findAll(), 'applicant_id', 'applicant_id') ...

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 are familiar with  jQueryUI's Sortable  class before starting this tutorial. Here are the basic steps to achieve this: Make sure your database table has a 'sortOrder' field. (Optional) Add the 'sortOrder' field to your Rules() function in your model Add the 'actionSort()' method to your controller to apply the sorting via ajax Add jQuery UI to your view that has the CGridView Setup the jQuery UI Code to work with the CGridView in question (Optional) Apply the sorting to your model's search() function if need be ...

PHP, Magic_Quotes. Getting rid of magic quotes issues

This is how i get rid of magic quotes issues on my PHP projects. function array_map_r( $func, $arr ) { $newArr = array(); foreach( $arr as $key => $value ) { $newArr[ $key ] = ( is_array( $value ) ? array_map_r( $func, $value ) : ( is_array($func) ? call_user_func_array($func, $value) : $func( $value ) ) ); } return $newArr; } if (get_magic_quotes_gpc()) { // Yes? Strip the added slashes $_REQUEST = array_map_r('stripslashes', $_REQUEST); $_GET = array_map_r('stripslashes', $_GET); $_POST = array_map_r('stripslashes', $_POST); $_COOKIE = array_map_r('stripslashes', $_COOKIE); } else { $_REQUEST = array_map_r('addslashes', $_REQUEST); $_GET = array_map_r('addslashes', $_GET); $_POST = array_map_r('addslashes', $_POST); $_COOKIE = array_map_r('addslashes', $_COOKIE); }