2009-12-23 138 views
1

我對cakePHP很陌生,到了我必須做分頁的時候。CakePHP find('threaded')分頁

評論表有一個parent_id和線程查詢工作正常,所以現在我想分頁結果。

我的問題是有限的sql查詢影響所有檢索的評論,我只想限制父母的,因爲另一種方式,它留下回復出查詢。

希望我會清楚,你可以幫助我。

謝謝。

+1

恐怕我不明白你的問題。請澄清「我的問題是有限的......」這句話,我會盡力協助。提供基本的模型結構(hasOne等),以及包含您期望的數組結構,以及它爲您提供的數組結構。謝謝! – 2009-12-23 17:48:35

+0

受限我的意思是我想限制查詢10個結果,但這個限制也會影響回覆。 – ozzysong 2010-01-15 09:51:57

回答

2

用途:

var $hasMany = array(
      'ChildComment' => array(
        'className' => 'ProfileComment', 
        'foreignKey' => 'parent_id', 
        'conditions' => '', 
        'dependent' => true, 
        'fields' => '', 
        'order' => 'created ASC' 
      ) 
    ); 

     var $belongsTo = array(
      'ParentComment' => array(
        'className' => 'ProfileComment', 
        'foreignKey' => 'parent_id', 
        'conditions' => '', 
        'fields' => '', 
        'order' => '' 
      )); 

,然後在查找:

$comments = $this->User->ProfileComment->find('all', array(
       'limit' => $this->incNumber, 
       'offset' => $page*$this->incNumber, 
       'conditions' => array('ProfileComment.parent_id' => null, 'ProfileComment.user_id' => $id), 
       'order' => 'ProfileComment.created DESC' 
      )); 

你要自定義代碼你的目的,但關鍵點是關係和查找條件有PARENT_ID =空值。這種方式的限制隻影響父母

0

您可能需要爲父母(主題?)執行查詢,然後針對下面的每棵樹執行另一個查詢。