Join 如何将联接查询结果更改为$this->;在cakephp中分页

Join 如何将联接查询结果更改为$this->;在cakephp中分页,join,pagination,cakephp-2.0,Join,Pagination,Cakephp 2.0,这是我的加入查询代码: $options['joins'] = array( array('table' => 'employees', 'alias' => 'Employees', 'type' => 'INNER', 'foreignKey' => 'employee_id',

这是我的加入查询代码:

$options['joins'] = array(
                array('table' => 'employees',
                    'alias' => 'Employees',
                    'type' => 'INNER',
                    'foreignKey' => 'employee_id',
                    // 'fields' => 'Users.user', <- get rid of this
                    'conditions' => array(
                        'TravancoDSREmployee.emp_id = Employees.employee_id'
                    )
                )
            );
        $options['fields'] = array('TravancoDSREmployee.*','Employees.*'); // <- insert this
        $options['conditions'] = array( 'TravancoDSREmployee.created_emp_id' => $emp_id);
        $result = $this->TravancoDSREmployee->find('all', $options);
        $this->set('result', $result);
$options['joins']=数组(
数组('table'=>'employees',
“别名”=>“员工”,
'类型'=>'内部',
'foreignKey'=>'employee_id',
//“字段”=>“用户.用户”,数组(
'TravancoDSREmployee.emp_id=Employees.employee_id'
)
)
);
$options['fields']=array('TravancoDSREmployee.*,'Employees.*');//$emp_id);
$result=$this->TravancoDSREmployee->find('all',$options);
$this->set('result',$result);
我想设置分页


我怎样才能做到这一点?

请查看下面给出的url

您可以尝试的代码是

$fields = array('TravancoDSREmployee.*','Employees.*'); // <- insert this
$conditions = array( 'TravancoDSREmployee.created_emp_id' => $emp_id);
$joins = array();
$joins[] = array(
    'table' => 'employees',
            'alias' => 'Employees',
            'type' => 'INNER',
            'foreignKey' => 'employee_id',
            // 'fields' => 'Users.user', <- get rid of this
            'conditions' => 'TravancoDSREmployee.emp_id = Employees.employee_id',
      );

$this->paginate = compact('fields' , 'joins' , 'conditions');
$result = $this->paginate('TravancoDSREmployee');
$this->set('result', $result);
$fields=array('TravancoDSREmployee.*,'Employees.*');//$emp_id);
$joins=array();
$joins[]=数组(
“表”=>“员工”,
“别名”=>“员工”,
'类型'=>'内部',
'foreignKey'=>'employee_id',
//'fields'=>'Users.user','TravancoDSREmployee.emp\u id=Employees.employee\u id',
);
$this->paginate=compact('fields','join','conditions');
$result=$this->paginate('TravancoDSREmployee');
$this->set('result',$result);
我希望这会对你有所帮助


谢谢

首先,您必须将条件传递给控制器中的分页属性。之后,可以调用paginate函数。Cange您的$result将成为:

$this->paginate = array('TravancoDSREmployee' => $options);
$result = $this->paginate('TravancoDSREmployee');
$this->set('result', $result);
好的,我明白了:

这是我的工作:

$this->paginate['TravancoDSREmployee'] = array(
            'limit' => 3, 
            'contain' => '', 
            'conditions' => array('TravancoDSREmployee.created_emp_id' => $emp_id),
            'fields' => array('TravancoDSREmployee.*','Employees.*'),
            'joins' => array(array('table' => 'employees', 'type' => 'INNER', 'alias' => 'Employees', 'conditions' => array('TravancoDSREmployee.emp_id = Employees.employee_id')))
            );
        $result = $this->paginate('TravancoDSREmployee');
        $this->set('result',$result);
我参考了此链接以获取解决方案:

我用您的代码更改了最后两行…我在视图中列出了结果…然后出现了错误,如…
未定义索引:Employees…
您必须更改视图以适应分页。分页和model->find('all'…)返回的数组不同。调试$result变量以显示返回的数组。还可以在视图上添加分页导航。不,您的页面有误。这不是分页的问题…问题在于连接功能。使用您的代码连接不起作用…请让我们在控制器文件中打印
$result
,然后退出。并检查其中的结果。