<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_view',
)); ?>
我需要这样的输出
__________________________
ID : 10 ID : 11
Name : XXX Name : YYYY
Age : 15 Age : 20
Place: abc Place:xyz
--------------------------
ID : 12 ID : 13
Name : aaa Name : sss
Age : 24 Age : 27
Place: vvc Place:xzss
--------------------------
如何为此更改我的_view.php
?
这是用于凭证打印,所以我需要降低纸张成本,这就是我寻求此解决方案的原因。
您可以使用Mohit Bhansali发布的HTML。但是你必须先添加更多的CSS:
.view {
float: left;
width: 250px; /* or other width */
}
然后在您的_view.php
中,您清除顶部的浮动,用于每个第二个项目。您可以使用预定义的$index
变量:
<?php if($index!=0 && $index%2==0): ?>
<div style="clear:left"></div>
<?php endif; ?>
你必须设置你设计的东西,这样:
<div class="view">
<table>
<tr>
<th><?php echo CHtml::encode($data->getAttributeLabel('ID')); ?>:</b></th>
<td><?php echo CHtml::link(CHtml::encode($data->id), array('view', 'id'=>$data->id)); ?></td>
</tr>
<tr>
<th><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b></th>
<td><?php echo CHtml::link(CHtml::encode($data->name), array('view', 'id'=>$data->name)); ?></td>
</tr>
<tr>
<th><?php echo CHtml::encode($data->getAttributeLabel('age')); ?>:</b></th>
<td><?php echo CHtml::link(CHtml::encode($data->age), array('view', 'id'=>$data->age)); ?></td>
</tr>
<tr>
<th><?php echo CHtml::encode($data->getAttributeLabel('place')); ?>:</b></th>
<td><?php echo CHtml::link(CHtml::encode($data->place), array('view', 'id'=>$data->place)); ?></td>
</tr>
</table>
</div>
设置一些 CSS:
<style>
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
</style>