控制器中方法:
public function actiontindex(){ $user = Yii::app()->user; $id = $user->id; $connection=Yii::app()->db; $sql= "sql查詢語(yǔ)句"; $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, )); }
視圖中顯示為:
第一部分為查詢的結(jié)果顯示:
<table class="table table-bordered"> <thead> <tr> <th class="per10">公文類型</th> <th class="per50">公文標(biāo)題</th> <th class="per15">當(dāng)前步驟</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>
第二部分為分頁(yè)的顯示:
<?php $this->widget('CLinkPager',array( 'header'=>'', 'firstPageLabel' => '首頁(yè)', 'lastPageLabel' => '末頁(yè)', 'prevPageLabel' => '上一頁(yè)', 'nextPageLabel' => '下一頁(yè)', 'pages' => $pages, 'maxButtonCount'=>8, 'cssFile'=>false, 'htmlOptions' =>array("class"=>"pagination"), 'selectedPageCssClass'=>"active" ) ); ?>
以上所述是小編給大家介紹的Yii1.1中通過(guò)Sql查詢進(jìn)行的分頁(yè)操作,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)網(wǎng)站的支持!
【網(wǎng)站聲明】本站除付費(fèi)源碼經(jīng)過(guò)測(cè)試外,其他素材未做測(cè)試,不保證完整性,網(wǎng)站上部分源碼僅限學(xué)習(xí)交流,請(qǐng)勿用于商業(yè)用途。如損害你的權(quán)益請(qǐng)聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。