May 8, 2013

SALT implementation in YII

A salt is a random data string that is used as an input to hash a password. The salt and the password are concatenated and encrypted with a cryptographic hash function and the output is then stored in the database. […]
June 18, 2011

Enable In-place Editing in Yii Grid

Today someone asked me for help to integrate Jeditable with Yii CGridView. So I thought why not write a little tutorial that can help others as well. In this article I assume that you are comfortable working with Yii; you […]
June 8, 2011

How to create custom validation rule

In the scenarios where validation rules provided by the Yii framework won’t handle your requirements, you can create custom validation rules. One example is the "authenticate" validation rule provided in "LoginForm" model of Yii blog demo. You can create your […]
April 26, 2011

Yii’s default validator Aliases

Below is the complete list of predefined validator aliases: boolean: alias of CBooleanValidator, ensuring the attribute has a value that is either CBooleanValidator::trueValue or CBooleanValidator::falseValue. captcha: alias of CCaptchaValidator, ensuring the attribute is equal to the verification code displayed in […]
April 12, 2011

Specifying nested relations for eager loading

Eager loading can be nested. For example, if for every comment, we also want to know its author, we could use the following ‘with’ find:   // find all posts together with their author and the author's profile Post::model()->with('author','author.profile')->findAll();  
April 12, 2011

Replace text box with drop down list in filter of CGridView

By default, Yii displays a textbox to search (filter) within results/records displayed by CGridView. In order to change those textboxes to drop down list (combo boxes), all you need to do is to assign an array to "filter" property of […]
April 9, 2011

Add conditions in search for relational tables

Let’s discuss example relationship given on following URL http://www.yiiframework.com/doc/guide/1.1/en/database.arr If you want to be able to filter results in grid using Posts’ author name then modify the search function of  Post model to similar to the one given below.
April 6, 2011

Change CGridView CSS file for entire application

To use your custom css file globally, set the cssfile property in config file   'components'=>array( 'widgetFactory'=>array( 'widgets' => array ( 'cssFile' => '/css/style-gridview.css', ) ), );  
April 3, 2011

Accessing modules method in Yii

Yii::app()->getModule('user')->encrypting($this->password)  or Yii::app()->controller->module->encrypting($this->password)  
April 3, 2011

Check for Ajax’ed request in Yii

if( Yii::app()->request->isAjaxRequest) {     // do some thing…. }
April 3, 2011

Session Handling in Yii

Yii::app()->session->add(‘product’, $productId); Yii::app()->session->get(‘product’); Yii::app()->session->remove(‘product’);
April 3, 2011

Send & retrieve cookies in Yii

To retrieve a cookie with the specified name: $cookie=Yii::app()->request->cookies[$name]; $value=$cookie->value;   To send a cookie:  $cookie=new CHttpCookie($name,$value); Yii::app()->request->cookies[$name]=$cookie;
April 3, 2011

Get & Set current language in Yii

To get current language:  $lang = Yii::app()->language;   To set current language: Yii::app()->language = ‘en’;
April 3, 2011

Get current Controller & action in Yii

 In view file  $this->uniqueid        (controller name) $this->action->Id      (action name) ($this is CController instance) In other files Yii::app()->controller->id  Yii::app()->controller->action->id
April 3, 2011

Get Id of an active form element in Yii

  CHTML::activeId($model,'attribute_name');  
March 25, 2011

CAutocomplete to display one value and submit another

  Source: http://www.yiiframework.com/wiki/25/using-cautocomplete-to-display-one-value-and-submit-another/ Don’t forget to use the attached Javascript and CSS files. This code does not work with jQuery UI auto complete. Javascript File CSS File
October 26, 2010

Correct way to access components in your modules

You can also configure modules’ components in the main config file   'modules'=>array( 'my'=>array( 'components'=>array( 'foo'=>array( 'class'=>'FooComponent', 'a'=>'hello', ), ), ), ),  
October 10, 2010

How to customize the error message of a validation rule

The following validation rule uses an error message that is different from the default one class Post extends CActiveRecord { public function rules() { return array( array('title, content', 'required', 'message'=>'Please enter a value for {attribute}.'), // ... other rules ); […]
October 9, 2010

DropDown for pageSize in CGridView

A convenient drop down to select page size and save in User state. Step 1: On top of my controller action for the gridview (if you used CRUD, this is actionAdmin() ) i added: // page size drop down changed if […]
October 8, 2010

Steps required to change project to production mode

Step 1: In config/main.php, add following element to "components" array 'cache'=>array( 'class'=>'system.caching.CApcCache', ),   Step2: In config/main.php, add following element to " components[‘db’] " array 'schemaCachingDuration' => 3600   Step 3: Comment out the following line of index.php defined('YII_DEBUG') or […]
October 6, 2010

Upload and resize image using YII

Download and extract this file in protected/extensions directory.   In config/main.php file, add the following element to components array  'image'=>array( 'class'=>'application.extensions.image.CImageComponent', 'driver'=>'GD', )   Now in action, insert the following code and modify paths $model->Picture = CUploadedFile::getInstance($model,'Picture'); if( is_object($model->Picture) ) […]
October 4, 2010

Automated display of flash messages

Step 1. Put this method into your WebUser class: public function getFlashKeys ( ) { $counters=$this->getState(self::FLASH_COUNTERS); if(empty($counters)) return array(); return array_keys($counters); }  
October 4, 2010

How to change content of a cell in Grid View to a link

If you want to link content of cell in Grid View to some page e.g In orders list, if you want customer’s name to be link that takes admin to customer’s detail page, change the columns of CGrid View as […]
October 4, 2010

Ajax button in CGridView

To add an ajax button to CGridView modify the buttons column  as   'columns' => array( 'id', 'name', array( 'class'=>'CButtonColumn', 'template' => '{view} {update} {delete}', 'buttons'=>array( 'view' => array( 'url'=>'"index.php?r=admin/view&id=".$data->user_id."&m=users"', 'click' => "function (){ $('#viewTab').load($(this).attr('href'));return false; }" ) ), ), […]
September 22, 2010

Working with flash messages in Yii

If you would like to inform the user, that his changes were successfully saved, you could add the following line to your Controller: Yii::app()->user->setFlash('success',"Data saved!");   Displaying the flash message in a view is done by if( Yii::app()->user->hasFlash('success') ) { […]
Working with flash messages in Yii
This website uses cookies to provide necessary website functionality, improve your experience and analyze our traffic. By using our website, you agree to our Privacy Policy and our cookies usage.
READ MORE