Thursday, 6 March 2014

How to show the Active/ Inactive dropdown status in YII C detail View

Its simple to set the active, inactive in the C detail View dropdown list, just assign the status value as like the below format

            'value'=>($model->status == 1) ? "Active" : "Inactive",

CActiveDataProvider Yii - Is simple and neat

CActiveDataProvider Yii - Is simple and neat, where we can enter our condition, pagination etc

I actually started coding with custom select query in YII, but while referred to "CActiveDataProvider" with conditions and pagination there is no need for to call the  sql query second time with condition or pagination

Here i will explain what i had previously and how the YII default CActiveDataProvider is working

My custom code in my controller function:

public function actionList()

$criteria = new CDbCriteria();

$count = Blog::model()->count($criteria);
$pages = new CPagination($count);

$pages->pageSize = 5;
$models = Blog::model()->findAll($criteria);
$this->render('list', array('models' => $models, 'pages' => $pages));

While following the above code, i need to call this $model inside a foreach and need to show the values. 

YII default CActiveDataProvider in my controller function:

public function actionList()
$criteria=new CDbCriteria;
$criteria->order='id DESC';  
$dataProvider=new CActiveDataProvider('Blog',array('criteria'=>$criteria,'pagination' => array('pageSize'=>Yii::app()->params['PaginationPerPage']),));

This is what Yii gave in default, its simple. And while following this code we can simply use the default view format from YII like below 

$this->widget('zii.widgets.CListView', array('dataProvider'=>$dataProvider,'itemView'=>'_view',));