入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

Yii1.1中通过Sql查询进行的分页操作

创建时间:2017-03-15 投稿人: 浏览次数:157
控制器中方法:
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"
    )
);
?>


声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。