Search code examples
phpyiiclistview

Displaying table records using CListview in Yii


I have a simple model named Service with attributes(ServiceId, name, description, Image) , and i want to display all the records in a view using CListview but only the name and description attribute, not all of them.

I am able to display the model but i cant find a solution to hide the id and image attributes.

Can anybody give a solution?

Thanks in advance.

Here is my Code :

Controller :

public function actionIndex()
{
    $model = new Service();

    $this->render('index',array(
        'model'=>$model,
    ));
}

and my View:

<h1>Services</h1>

<?php 

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

Solution

  • The answer is to change your model's view. It is propably located in protected/views/service/_view.php, where service is your's controller name.

    You can delete lines related to displaying ids and other attributes or change formatting.