2012-02-25 78 views
-1

我使用cakephp 1.3,我收到奇怪的分頁問題。我有不完整的分頁爲我有多個控制器工作分頁代碼。但我的控制器的其餘部分不顯示下一個和以前的按鈕和分頁號工作正常 我使用在我看來cakephp分頁下一頁和以前沒有顯示

<?php 
    if(!empty($zipcodes)){ 
     echo "<div class='pagination'>"; 
     echo @$this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); 
     echo @$this->Paginator->numbers(); 
     echo @$this->Paginator->next('Next »', null, null, array('class' => 'disabled')); 
     echo '<div style="float:right;padding:5px;color:#000">'.$this->Paginator->counter().'</div>'; 
     echo "<div class='clear'></div>"; 
     echo "</div>"; 
    } 
?> 

而且在我的控制器這段代碼我已經使用分頁器,因爲我自定義分頁查詢結果。我包括分頁代碼app_model.php 。 我ontroller代碼

var $paginate = array(
         'Zipcode' => array('limit' => 5, 
             'order' => array('id' => 'desc'),           


        ) 
        ); 

我的查詢和操作

 $tsql = " SELECT Zipcode.* ". 
        " FROM zipcodes AS Zipcode ". 
        " WHERE Zipcode.region_id=0 "; 
       $conditions = array(
           'tsql'=>$tsql, 
          ); 
       $tmp = $this->paginate('Zipcode',$conditions); 
       $this->set('zipcodes', $tmp); 

任何一個可以指出我我在做什麼,爲什麼wrong.??And分頁正在爲只有一些控制器。??? THANKs提前

回答

1

首先,在控制器的頂部更改您的分頁。從中刪除郵編。它應該只是:

var $paginate = array(
    'limit' => 5, 
    'order' => array('Zipcode.id' => 'desc'),           
); 

其次,我不知道你想什麼用$ TSQL來完成,但據我所知,你不能傳遞一個SELECT語句作爲條件。你需要寫ORM具體情況是這樣的:

$this->paginate = array(
    'conditions' => array('Zipcode.region_id' => 0), 
); 

然後設置郵編,你可以這樣做:

$this->set('zipcodes', $this->paginate('Zipcode')); 

或本

$data = $this->paginate('Zipcode'); 
$this->set(compact('data')); 

作爲一個側面說明,echo @$this->Paginator->prevecho $this->Paginator->prev和所有@應該從這些行中刪除。這是糟糕的編碼習慣。我不確定你是否因爲某種原因而忽視它,但這很糟糕。

+0

不,我一直在我的社區網站上使用上述方法......並且工作正常......但一些控制器使問題......和關於@ ..我用它來逃避如果價值是空的..thnx爲你的努力brither ...希望我可以通過它再次與您的建議.. – jack 2012-02-25 10:28:29

+0

使用'$ tsql'是不正確的,除非你有一些自定義的方法來處理它在別的地方。我試圖產生這個,我得到一個錯誤。它在查詢中設置條件以查找Zipcode表中的'tsql'列。如果你搞亂CakePHP ORM的定製,沒有人能夠爲你回答這個問題。你真的應該以正確的方式使用CakePHP或手動代碼。但是,你寫在你的文章中的方式是不正確的。 – 2012-02-25 15:12:13

+0

我已經發送郵件詳細..這個郵件:[email protected] – jack 2012-02-27 09:33:40