Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make custom CListlView widget in yii

Tags:

yii

I am developing my web application in the Yii framework . I do not have enough experience in the Yii framework. I want to make the view for the index post page. The Yii provide the CListView for this, but I want to make some customization on that.

like image 535
binesh Avatar asked Jan 20 '23 23:01

binesh


2 Answers

You can extend a widget with the following steps:

Copy CListView.php from /(yii root)/framework/zii/widgets to /(application root)/protected/widgets

Rename the file BineshListView.php

Open BineshListView.php. Add this before the class declaration

Yii::import("zii.widgets.CListView");

Change the first line of the class declaration to:

class BineshListView extends CListView { ...

Now, you have your own BineshListView class you can customize. To use it in a view, you can call it like you would CListView

$this->widget('application.widgets.BineshListView', array( 'data'=>$model, etc... ) );

Let me add that BineshListView will inherit all the properties and methods of CListView. Therefore, if you do not need to customize a property or method and want to use the original behavior of CListView, you can delete the property or method from BineshListView.

like image 176
2 revs Avatar answered Jan 31 '23 02:01

2 revs


you no need to customize the ClistView . just simply make changes in the partial view file . which is called by the ClistView.

<?php
$this->widget('zii.widgets.ClistView',arrray(
      'dataprovider'=>$your-data-provider,
      'view-file'=>'custom-view-file'
));

?>

make changes in custom-view-file. make sure the custom-view-file in same views folder for the controller.

like image 32
Kaletha Avatar answered Jan 31 '23 02:01

Kaletha