简体   繁体   中英

how to use Where condition in Pagination using cakephp

Here i am using three categories. I want to fetch the data from a particular category while using pagination.

My code:

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');
    */

}

Use the following

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM