Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp:对搜索结果使用连接_Cakephp - Fatal编程技术网

cakephp:对搜索结果使用连接

cakephp:对搜索结果使用连接,cakephp,Cakephp,我现在完全弄糊涂了 我有三个表格:申请人,申请人资格,和资格 在申请者的索引视图中,我有一个带有资格下拉列表的表格。结果应该是具有该资格的申请人名单 所以我需要索引视图中的申请者表基于联接,对吗 如果我将此添加到我的申请者\ U控制器: $options['joins'] = array( array( 'table' => 'applicants_qualifications', 'alias' => 'q',

我现在完全弄糊涂了

我有三个表格:
申请人
申请人资格
,和
资格

在申请者的索引视图中,我有一个带有资格下拉列表的表格。结果应该是具有该资格的申请人名单

所以我需要索引视图中的申请者表基于联接,对吗

如果我将此添加到我的申请者\ U控制器:

$options['joins'] = array(  
    array(  
        'table' => 'applicants_qualifications',  
        'alias' => 'q',  
        'type' => 'left outer', // so that I get applicants with no qualifications too   
        'conditions' => array('Applicant.id = q.applicant_id',)  
    )  
);
$this->Applicant->find('all', $options);
我在页面底部得到了一条附加的sql语句,其中包含左侧的外部联接,但是没有联接的sql也在那里

我认为这句话:

$this->set('applicants', $this->paginate());
调用不带联接的sql语句

看起来我需要将join$选项与paginate调用结合起来。是这样吗

如果我使用搜索表单,我会在“where子句”中得到:未知列“Qualifications.qualification\u id”

因此,页面显然还没有“使用”我的sql连接


对不起,我还是个笨蛋。感谢您的任何帮助…

为了为您的模型分页设置
条件
连接
,您必须按照以下操作:

function admin_index() {
    $this->Applicant->recursive = 0;
    $this->paginate = array(
        'Applicant' => array(
            // 'conditions' => array('Applicant.approved' => true),
            'joins' => array(
                array(
                    'table' => 'applicants_qualifications',  
                    'alias' => 'ApplicationsQualification',  
                    'type' => 'left outer',
                    'conditions' => array('Applicant.id = ApplicationsQualification.applicant_id')  
                )
            )
            // 'order' => array('Applicant.joined DESC')
        )
    );
    $this->set('applicants', $this->paginate());
}
我已经注释掉了一些您稍后可以包含的示例键-只是为了让您了解它是如何工作的


希望有帮助

您可以使用内部联接而不是左外部联接

现场控制器

$cond =   array(
            array(
                'table' => 'colleges',
                'alias' => 'Colleges',
                'type' => 'inner',

                'conditions'=> array('Colleges.college_id = Courses.college_id')
            )

            ) ;


        $courses = $this->Courses->find('all',  
            array('joins' =>$cond,'conditions' => array("Courses.status ='1' AND Colleges.status='1' "),
                    'order'=>array('course_name'),
                    'fields' => array('course_id','course_name'),'group'=>'Courses.course_id'
                )
          );

再次感谢RabiFire!工作完美。我喜欢cakephp和stackoverflow!