Yii1.1中通過Sql查詢進行的分頁操作方法
更新時間:2017年03月16日 10:19:25 作者:我只是艾特
這篇文章主要介紹了Yii1.1中通過Sql查詢進行的分頁操作方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
控制器中方法:
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"
)
);
?>
以上所述是小編給大家介紹的Yii1.1中通過Sql查詢進行的分頁操作,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
ThinkPHP中I(),U(),$this->post()等函數(shù)用法
這篇文章主要介紹了ThinkPHP中I(),U(),$this->post()等函數(shù)用法,簡單分析了ThinkPHP處理表單的常用函數(shù)使用方法,具有一定的參考借鑒價值,需要的朋友可以參考下2014-11-11
PHP設計模式之裝飾器(裝飾者)模式(Decorator)入門與應用詳解
這篇文章主要介紹了PHP設計模式之裝飾器(裝飾者)模式(Decorator),結合實例形式詳細分析了PHP裝飾者模式的概念、原理、用法及相關操作注意事項,需要的朋友可以參考下2019-12-12
在laravel中實現(xiàn)ORM模型使用第二個數(shù)據(jù)庫設置
今天小編就為大家分享一篇在laravel中實現(xiàn)ORM模型使用第二個數(shù)據(jù)庫設置,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

