【问题标题】:how to use Where condition in Pagination using cakephp如何使用 cakephp 在分页中使用 Where 条件
【发布时间】:2015-08-26 15:47:05
【问题描述】:

这里我使用了三个类别。我想在使用分页时从特定类别中获取数据。

我的代码:

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

}

【问题讨论】:

    标签: php cakephp pagination cakephp-2.0


    【解决方案1】:

    使用下面的

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

    【讨论】:

    • $this->Paginator->settings['contain'] = array('Users','KnowledgeReply'=>array('Users') ); $this->set('KnowledgeSolutions', $this->Paginator->paginate());
    • 感谢回复,但我上面的代码有问题,请提供一些其他解决方案
    • @Anns,分享你的架构关系好吗?我觉得你应该红CakePHP Paginate conditions on Join Table
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 2020-06-28
    相关资源
    最近更新 更多