YII Framework Archive

Pagination example in Php Yii Framework

Pagination example in Php Yii Framework While working we need to perform pagination.  Whether to show the list of articles, users or products, we need pagination. In Yii it is very easy to implement pagination. function actionSearch(){ $criteria = new CDbCriteria(); $count=Article::model()->count($criteria); $pages=new CPagination($count); // results per page $pages->pageSize=10; $pages->applyLimit($criteria); $models = Post::model()->findAll($criteria); $this->render('index', array( 'models'

Include JavaScript and CSS file in Yii Framework

Include JavaScript and CSS file in Yii Framework While working on a project in YII in beginning I came to know a very nice way of including JavaScript and CSS style files in the Layout / View file  in YII Framework. In YII we use clientScript->registerCoreScript and clientScript->registerCssFile functions. Please see the code below. <?php

Yii Framework- Creating hidden field

In Yii framework we can create a hidden field using model and without model as described below 1. Creating hidden field without model. echo CHtml::hiddenField('name' , 'value', array('id' => 'name')); 2. Creating hidden field with model. echo $form->hiddenField($model, 'name');

YII – Get Controller name

In Yii framework if we want to get name of current controller name. It can be done by following command. <?php Yii::app()->controller->id; ?>  

YII – Get name of current controller’s action

In Yii framework if we want to get name of current controller’s action. It can be done by following command. <?php echo Yii::app()->controller->action->id ?>          

YII – Changing Language

If we want to change language of a particular action in YII or for the whole application we need to , set CApplication::language . This can be done at runtime as in Yii::app()->language = 'fr'; but we can also do it in application configuration: array( // ...settings... 'language' => 'fr', // ...more settings... )