From many features of yii one is its predefined gridview and list view funstions . Because in almost every applications we need to display the data from the database table .We can display data with Cgridview and clistview. Additionally we can use ajax search, and ajax filters, ajax pagination in the table . Today i am going to discuss how can we customize these views .

First of all we need to fetch a data from database .You can fetch the data with a couple of ways . CActiveDataProvider is the class by which we can fetch the data . here is an example .

$dataprovider=new CActiveDataProvider('Modelclass',array(
'criteria'=>array(
'condition'=>'column=value' //  you can define your condition
),
'sort'=>array(
'defaultOrder'=>'created DESC',    // default sort order
),
'pagination' => array( 
'pageSize' =>20,   // set your pagination limit here 
)));

Now in the view file you can display records like this . You can use two ways to show results Cgridview and Clistview. Here is the example of Cgridview , The data will display in the tabel .

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'id for view',   // specify an id for view
'htmlOptions'=>array('class'=>'table-responsive'),   // specify the html options
'itemsCssClass'=>'table table-hover table-bordered',   // tabel classes
'dataProvider'=>$dataprovider, // pass the data here 
'filter'=>$model,
'columns'=>array(
'id',
'title',
'parent',   // you can use column name directly  
// need an html data ?
array(
'name' => 'created',
'type'=>'raw',
'value' => function($data){
return '<span class="time">'.$data->created.'</span>';
},
),
array(
'class'=>'CButtonColumn',   // buttons to perform edit, view , delete action 
),
),
));

Second option is Clistview . You need to define a view file to display the data .

$lw = $this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataprovider,
'itemView' => '_view',
'viewData' => array( 'var1' =>'value','val2' =>'value'),    // YOUR OWN VARIABLES
'htmlOptions'=>array('class'=>'classname'),   // define your classname here
'pager' => array(
'header' => false,
'htmlOptions'=>array('class'=>"pagination"),
'selectedPageCssClass'=>'active'
),
'summaryText' => '',
'sortableAttributes' => array(
),
));

With this way the html will render from your defined view file . Here is an example of _view.php data will available in $data variable .

<div class="col-md-6 col-sm-6">
<a href="<?php echo $this->createurl('/someurl/',array('id'=>$data->id)); ?>" >
<h3><?php echo $data->title; ?></h3>
</a>
<p>
<?php echo $data-description; ?>
</p>
</div>
http://codingbin.com/wp-content/uploads/2016/02/Untitled-1-copy.jpghttp://codingbin.com/wp-content/uploads/2016/02/Untitled-1-copy-150x150.jpgdevidframeworksYiiFrom many features of yii one is its predefined gridview and list view funstions . Because in almost every applications we need to display the data from the database table .We can display data with Cgridview and clistview. Additionally we can use ajax search, and ajax filters,...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request