cakephp 3.5中的join和virtualFields

时间:2018-01-03 14:08:48

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.4

我需要在index.ctp中使用分页加入和虚拟字段。我写了相同的代码,正在使用cakephp 2.x,但在cakephp 3.5中,以下代码无效。当我正在服用' pdt'显示错误 TestRequest与pdt 无关,当我采取单独的字段时,也会出现错误未知列' TestRequest.pdt'在'字段列表'

我需要更正以下代码?

public function index()
{
    $this->paginate = [
        'contain' => ['OwnerCompanies', 'ProductsMaster','TestRequestDet'],
        //'fields' => ['pdt'],
        'joins' => [                    
                [                       
                     'table' => 'product_data_tests',
                     'alias' => 'pdt',
                     'conditions'=> array('TestRequestDet.test_id = pdt.id'),
                     'type' => 'left'   
                ]
    ] ];       

    $this->TestRequest->virtualFields = [
            'test_name'=>'pdt.test',
            'specification'=>'pdt.specification',
            'method'=>'pdt.methods',
    ];
    $testRequest = $this->paginate($this->TestRequest);

    $this->set(compact('testRequest'));
    $this->set('_serialize', ['testRequest']);
}

0 个答案:

没有答案