binesh
binesh

Reputation: 213

how to make custom CListlView widget in 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.

Upvotes: 4

Views: 2788

Answers (2)

Kaletha
Kaletha

Reputation: 3239

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.

Upvotes: 3

siliconrockstar
siliconrockstar

Reputation: 3664

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.

Upvotes: 6

Related Questions