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查询进行的分页操作,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对积木网网站的支持!
ThinkPHP3.2框架使用addAll()批量插入数据的方法
本文实例讲述了ThinkPHP3.2框架使用addAll()批量插入数据的方法。分享给大家供大家参考,具体如下:thinkphp中model类的addAll()方法可以将数据同时添加到数
thinkPHP框架可添加js事件的分页类customPage.class.php完整实例
本文实例讲述了thinkPHP框架可添加js事件的分页类customPage.class.php。分享给大家供大家参考,具体如下:用于ajax动态加载数据的分页类,分页事件可以动态
thinkPHP5.0框架环境变量配置方法
本文实例讲述了thinkPHP5.0框架环境变量配置方法。分享给大家供大家参考,具体如下:允许使用环境变量配置,并且优先级别比在配置文件中要高,因为
编辑:一起学习网
标签:分页,框架,给大家,方法,实例