【问题标题】:how to paginate in cakephp when result comes from several join conditions当结果来自多个连接条件时如何在 cakephp 中分页
【发布时间】:2016-09-06 08:20:27
【问题描述】:

我在 cakephp 分页中遇到问题。在深入之前,我想显示一些我在控制器中执行的代码

$this->paginate = array(
 'joins' => array(
                array(
                        'table' => 'job_posting_lists',

                        'conditions'=> array('job_posting_lists.firm_id')),
                        array(
                        'table' => 'firmsdetails',
                        'alias' => 'st',
                        'conditions'=> array('st.id')),
                ),               
            'conditions' =>array('job_posting_lists.select_industry'=>$id,'job_posting_lists.verify'=>1),
            'fields' => array('job_posting_lists.*','st.*'),
            'limit' => 3,

            'contain' => array('job_posting_lists'));

        $ListjobBycategories = $this->paginate(); 
        echo "<pre>";print_r($ListjobBycategories); die;
        $this->set('jobbycat',$ListjobBycategories);

ListjobBycategories 中的结果正确,但它返回更多关于 1230 的数据,在我的 job_posting_datas 中只有 5 行,下一页返回与我所做的相同的结果

【问题讨论】:

  • 我要对 $ListjobBycategories 数据进行分页

标签: php mysql cakephp pagination


【解决方案1】:

试试这个代码,根据你的代码做适当的修改,

$this->paginate = array(
     'joins' => array(
          array(
            'table' => 'tbl1',
            'alias' => 'alias1',
            'conditions'=> array('')
          ),array(
            'table' => 'tbl2',
            'alias' => 'alias2',
            'conditions'=> array('')
          ),array(
            'table' => 'tbl3',
            'alias' => 'alias3',
            'type' => 'left',
            'conditions'=> array('')
          ),
        ),               
                'conditions' => $displayConditions, // Your query conditions
                'fields' => $this->displayFields, // Your field set which you want to retrieve from tables
                'limit' => $show_page,// number of records you wish to retrieve in each page
                'group' => '', // field by which wish to grouping your data set
                'contain' => array(''),//It will contain name of all the Models which are in Join
            );

            $ListjobBycategories = $this->paginate(); // Call pagination function, it will retrieve all records 

如果有任何疑问,请告诉我。

【讨论】:

  • 在我给出连接条件或主要条件的条件下
  • 条件将包含“主要条件”,对于连接,您需要添加另一个元素“连接”并在那里添加您的连接条件。
  • 现在请检查我编辑的答案。我认为它会更好地帮助你
  • 'table' =>'firmsdetails','job_posting_lists',给出错误
  • 谢谢它的工作..你能给我代码查看分页如何显示数字。
猜你喜欢
  • 1970-01-01
  • 2011-03-24
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-15
  • 2015-08-20
相关资源
最近更新 更多