Reputation: 3
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',
));
?>
Upvotes: 0
Views: 177
Reputation: 1264
Go to your protected/views/service/_view.php Update below code
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->name), array('view', 'id'=>$data->name)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->description), array('view', 'id'=>$data->description)); ?>
<br />
</div>
Upvotes: 0
Reputation: 4023
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.
Upvotes: 0