首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一张桌子的分页

一张桌子的分页
EN

Stack Overflow用户
提问于 2015-09-15 03:43:23
回答 1查看 834关注 0票数 0

我用的是Yii应用程序。其中,如何对表内容进行分页(不使用cgridview)。

config/main.php

代码语言:javascript
复制
'params'=>array(
    'adminEmail'=>'webmaster@example.com',
    'listPerPage'=> 10,//default pagination size
),

控制器中的

代码语言:javascript
复制
  public function actionOutbox() {
    $criteria = new CDbCriteria;
    $criteria->condition = 'from_userid = :id';
    $criteria->order = 'time DESC';
    $criteria->params = array (':id'=>Yii::app()->user->id);

    $item_count = Email::model()->count($criteria);
    $model      = Email::model()->findAll($criteria);

    $pages = new CPagination($item_count);
    $pages->setPageSize(Yii::app()->params['listPerPage']);
    $pages->applyLimit($criteria);

    $this->render('outbox', array(
        'model' => $model,
        'item_count'=>$item_count,
        'page_size'=>Yii::app()->params['listPerPage'],
        'items_count'=>$item_count,
        'pages'=>$pages,
    ));
}

In View,

代码语言:javascript
复制
 <table data-provides="rowlink" data-page-size="20" data-filter="#mailbox_search" class="table toggle-square default footable-loaded footable" id="mailbox_table">
                            <thead>
                                <tr>
                                    <th></th>
                                    <th data-hide="phone,tablet">To</th>
                                    <th>Subject</th>
                                    <th data-hide="phone" class="footable-last-column">Date</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($model as $item) {
                                    if ($item->email_status == 1)
                                        echo '<tr id="' . $item->emailid . '" class="unreaded rowlink" style="display: table-row;">';
                                    else
                                        echo '<tr id="' . $item->emailid . '" class="rowlink" style="display: table-row;">';
                                    echo '<td class="nolink footable-first-column">';
                                    echo '<span class="footable-toggle"></span>';

                                    echo '</span></td>';
                                    echo '<td>' . $item->touser->username . '</td>';
                                    echo '<td>' . $item->email_subject . '</td>';
                                    $originalDate = $item->time;
                                    $newDate = date("Y-M-d H:i:s", strtotime($originalDate));


                                    echo '<td class="footable-last-column">' . $newDate . '</td></tr>';
                                }
                                ?>
                            </tbody>
                        </table>
<?php
  $this->widget('CLinkPager', array(
        'currentPage' => $pages->getCurrentPage(),
        'itemCount' => $item_count,
        'pageSize'=> $page_size,
        'maxButtonCount' => 5,
        //'nextPageLabel' =>'My text >',
        'htmlOptions' => array('class'=>'pages'),
    ));
     ?>

通过使用此代码,当前页大小无法工作。将显示表中的完整值。我也将页面大小从10更改为2,但没有工作。

我做错了什么?

请帮帮我。提前感谢

EN

回答 1

Stack Overflow用户

发布于 2015-09-15 05:25:31

你不受限制地使用findAll,想让我理解分页吗?

使用CGridView小部件代替它,并在DataProvider中设置分页(不创建单独的分页对象:,它不能提供结果计数)。

请阅读本题

谢谢。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32577336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档