繁体   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