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 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 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