2015-09-15 71 views
0

我正在使用Yii應用程序。在那個如何給表分頁的內容(不使用cgridview)。yii中的表格分頁

配置/ main.php

'params'=>array(
    'adminEmail'=>'[email protected]', 
    'listPerPage'=> 10,//default pagination size 
), 

在控制器,

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, 
    )); 
} 

在View,

<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,但不起作用。

我在做什麼錯?

請幫幫我。在此先感謝

+4

[yii中表格內容的分頁]可能重複(http://stackoverflow.com/questions/32523304/pagination-for-a-table-contents-in-yii) –

回答

1

您使用findAll沒有限制,並希望yii瞭解分頁?

使用CGridView小部件,而不是它在DataProvider設置分頁(不分頁創建單獨的對象:它不affort導致計數)。

並請閱讀this topic

謝謝。