简体   繁体   中英

Custom CListView in Yii framework

I wanted to modify the default list view provided by the Yii framework. The current view display everything as a row 在此输入图像描述 . What I want is to display the information in following format 在此输入图像描述 . Could you suggest me how can I extend this widget and create my own view. I have attached both needed as a image. I am new to Yii so all help would be really appriciable. If there is already any widget in this format I would be so happy.

Content for my view File would be

    <?php
/* @var $this LeosafealertController */
/* @var $data Leosafealert */
?>

<div class="view">  
    <b><?php echo CHtml::encode($data->getAttributeLabel('id')); ?>:</b>
    <?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?>
        <br/>
    <b><?php echo CHtml::encode($data->getAttributeLabel('date')); ?>:</b>
    <?php echo CHtml::encode($data->date); ?>
        <br/>
    <b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
    <?php echo CHtml::encode($data->description); ?>
        <br/>
    <b><?php echo CHtml::encode($data->getAttributeLabel('photo')); ?>:</b>
    <?php echo CHtml::image($data->getImageURL().$data->photo,$data->photo); ?>
        </br>
        <b><?php echo CHtml::encode($data->getAttributeLabel('link')); ?>:</b>
    <?php echo CHtml::link(CHtml::encode("click here"), $data->getFileURL().$data->link,array('target'=>'_blank')); ?>
</div>

Can you not edit your view file (eg just edit '/path/to/model/views/_view.php', or whatever your view file is called)?

You can also declare your own css file for a CLitView by defining a cssFile property. ie;

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
    'cssFile'=>'/css/myCssFile.css',
    ...
));

You could create your own css file for your layout and use that for every CListView you want with the given layout?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM