簡體   English   中英

如何使用cakephp在分頁中使用Where條件

[英]how to use Where condition in Pagination using cakephp

我在這里使用三個類別。 我想在使用分頁時從特定類別中獲取數據。

我的代碼:

public function index( $category_id = null )
{
    if (!$this->KnowledgeSolution->KnowledgeCategory->exists( $category_id ))
    {
        throw new NotFoundException(__('Invalid Knowledge Category'));
    }
    $KnowledgeCategory = $this->KnowledgeSolution->KnowledgeCategory->read(null,$category_id);
    $this->set('KnowledgeCategory', $KnowledgeCategory);

    $this->Paginator->settings['contain'] = array('Users', 'KnowledgeReply'=>array('Users') );
    $this->set('KnowledgeSolutions', $this->Paginator->paginate());    
    /* 
        $this->paginate = array('conditions' => array('Product .title LIKE' => 'a%'),'limit' => 10 );
        $data = $this->paginate('Product');
    */

}

使用以下

public function index( $category_id = null )
{
    if (!$this->KnowledgeSolution->KnowledgeCategory->exists( $category_id ))
    {
        throw new NotFoundException(__('Invalid Knowledge Category'));
    }
    $KnowledgeCategory = $this->KnowledgeSolution->KnowledgeCategory->read(null,$category_id);
    $this->set('KnowledgeCategory',$KnowledgeCategory);

    $this->Paginator->settings['contain'] = array('Users','KnowledgeReply'=>array('Users') );
    $this->set('KnowledgeSolutions', $this->Paginator->paginate());    

    $this->Paginator->settings = array('conditions' => array('Product .title LIKE' => 'a%'),'limit' => 10 );

    $data = $this->Paginator->paginate('Product');
    $this->set(compact('data'));
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM