我的分页遇到了一些问题。 这是我的代码。
控制器:
public function actionIndex()
{
$model=new Order;
$criteria = new CDbCriteria;
$total = Order::model()->count($criteria);
$pages = new CPagination($total);
$pages->setPageSize(Yii::app()->params['listPerPage']);
$pages->applyLimit($criteria);
// $posts = konsumen::model()->findAll($criteria);
$this->render('index',
array('model'=>$model,
// 'list'=>$posts,
'pages' => $pages,
'item_count'=>$total,
'page_size'=>Yii::app()->params['listPerPage'],)) ;
}
查看:
$result = "SELECT * FROM order where date between '$date_first' and '$date_last' and status $status order by id desc";
$list = DetailPesanan::model()->findAllBySql("$result");
if($list)
{
?>
<div class="tablebx" style="padding-left: 5px; padding-right: 5px;"><!-- End div class="pagecon" -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="tablebx_topbg">
<td><?php echo Yii::t('consumen','No.');?></td>
<td><?php echo Yii::t('consumen','Date');?></td>
<td><?php echo Yii::t('consumen','Quantity');?></td>
<td><?php echo Yii::t('consumen','Debt');?></td>
<td><?php echo Yii::t('consumen','Profit');?></td>
</tr>
<?php
if(isset($_REQUEST['page']))
{
$i=($pages->pageSize*$_REQUEST['page'])-9;
}
else
{
$i=1;
}
$cls="even";
?>
<?php
foreach($list as $list_1)
{
?>
<tr class=<?php echo $cls;?>>
<td><?php echo $i; ?></td>
<td><?php echo $list_1->date ?></td>
<td><?php echo $rp=number_format($list_1->quantity, 0, ',', '.') ?> Pcs</td>
<td>Rp. <?php echo $rp=number_format($list_1->debt, 0, ',', '.') ?></td>
<td>Rp. <?php echo $rp=number_format($list_1->profit, 0, ',', '.') ?></td>
</tr>
<?php
if($cls=="even")
{
$cls="odd" ;
}
else
{
$cls="even";
}
$i++;
}
?>
</table>
<div class="pagecon">
<?php
$this->widget('CLinkPager', array(
'currentPage'=>$pages->getCurrentPage(),
'itemCount'=>$item_count,
'pageSize'=>$page_size,
'maxButtonCount'=>5,
//'nextPageLabel'=>'My text >',
'header'=>'',
'htmlOptions'=>array('class'=>'pages'),
));?>
</div> <!-- END div class="pagecon" 2 -->
<div class="clear"></div>
</div> <!-- END div class="tablebx" -->
<?php
}
else
{
echo '<div class="listhdg" align="center">'.Yii::t('consument','data cannot found').'</div>';
}?>