how to use Where condition in Pagination using cakephp

563 Views Asked by At

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

}
1

There are 1 best solutions below

3
On

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