SELECT e.employee_name, e.employee_store, e.employee_phone, s.store_address
FROM `employee` e
JOIN store s ON e.employee_store = s.store_name
이 쿼리를 cakephp 컨트롤러에 쓰는 방법과 뷰 파트에 결과를 표시하는 방법.cakephp에 두 개의 테이블 쿼리를 결합하는 방법
SELECT e.employee_name, e.employee_store, e.employee_phone, s.store_address
FROM `employee` e
JOIN store s ON e.employee_store = s.store_name
이 쿼리를 cakephp 컨트롤러에 쓰는 방법과 뷰 파트에 결과를 표시하는 방법.cakephp에 두 개의 테이블 쿼리를 결합하는 방법
시도로 -
$this->Model->find(
'all',
array(
'fields' => array('table.employee_name', 'table.employee_store', ....),
'joins' => array(
'table' => 'store',
'conditions' => array('employee_store' => 'store_name')
)
)
)
이 직원이 모델명 시도해야, 저장 테이블의 이름이고 유형은이 오른쪽, 왼쪽 합류 및 내부
$details=$this->Employee->find('all',array('fields' => array('Employee.*','stores.*'),
'joins'=>array(
array(
'table'=>'store',
'type'=>'inner',
'conditions'=>array('Emmployee.employee_store=stores.store_name')
)
)
)
);
$this->employee->bindModel(
array('hasMany' => array(
'Store' => array(
'className' => 'Principle'
)
)
)
);
내가 모델, 컨트롤러에 쓸 필요가있는 세부 사항을 설명 할 수있다. 보기 부분. – user3576366
e.employee_name, e.employee_store, e.employee_phone, s.store_address이 열을 뷰 파에서 표시하려고합니다. t. – user3576366
이 답변을 업데이트했습니다. 별칭을 사용하지 않아도됩니다. 이 경우 Modelname 또는 테이블 이름을 사용할 수 있습니다. –
오류가 발생합니다 : 정의되지 않은 오프셋 : 0 [CORE \ Cake \ Model \ Datasource \ DboSource.php, 1915 줄], 문자열 변환 [CORE \ Cake \ Model \ Datasource \ DboSource.php, 줄 1928] 배열에 – user3576366