控制器中方法:
public function actiontindex(){
$user = Yii::app()->user;
$id = $user->id;
$connection=Yii::app()->db;
$sql= "sql查詢語句";
$command = $connection->createCommand($sql)->queryAll();
$pages = new CPagination(count($command));
$list = $connection->createCommand($sql." limit ".$pages->limit." offset ".$pages->offset."")->queryAll();
$this->render('index',array(
'bonus' => $list,
'pages' => $pages,
));
}
檢視中顯示為:
第一部分為查詢的結果顯示:
<table class="table table-bordered">
<thead>
<tr>
<th class="per10">公文型別</th>
<th class="per50">公文標題</th>
<th class="per15">當前步驟</th>
<th class="per15">日期</th>
</tr>
</thead>
<tbody>
<?php if (isset($bonus)):?>
<?php foreach ($bonus as $key=>$ad): ?>
<tr>
<td><?=$ad['typeName'] ?></td>
<td><?=$ad['doc_title'] ?></td>
<td><?=$ad['taskname'] ?></td>
<td><?=date("Y-m-d H:i:s",$v['create_time']) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
第二部分為分頁的顯示:
<?php
$this->widget('CLinkPager',array(
'header'=>'',
'firstPageLabel' => '首頁',
'lastPageLabel' => '末頁',
'prevPageLabel' => '上一頁',
'nextPageLabel' => '下一頁',
'pages' => $pages,
'maxButtonCount'=>8,
'cssFile'=>false,
'htmlOptions' =>array("class"=>"pagination"),
'selectedPageCssClass'=>"active"
)
);
?>