저는 CakePHP에서 인보이스 프로젝트를하고 있습니다. 모델에서 관련 테이블을 설정했지만 어떻게 든보기로 전달하지 않습니다. CakePHP - 관련 값이 표시되지 않습니다.
이들은
내 모델입니다 :class Invoice extends AppModel {
public $hasOne = array(
'Customer' => array(
'className' => 'Customer',
'foreignKey' => 'id'
),
'Project' => array(
'className' => 'Project',
'foreignKey' => 'id'
),
);
...
프로젝트 모델
송장 모델
class Project extends AppModel {
public $hasOne = array(
'Customer' => array(
'className' => 'Customer',
'foreignKey' => 'id'
)
);
public $hasMany = array(
'Invoice' => array(
'className' => 'Invoice',
'foreignKey' => 'project_id'
),
);
고객 모델
class Customer extends AppModel {
public $virtualFields = array(
'full_name' => 'CONCAT(Customer.frontname, " ", Customer.lastname)',
'display_name' => 'IF(Customer.company > " ", Customer.company, CONCAT(Customer.frontname, " ", Customer.lastname))',
);
public $hasMany = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'customer_id',
),
'Invoice' => array(
'className' => 'Invoice',
'foreignKey' => 'customer_id',
),
);
그리고보기 :
<?php
foreach($invoices as $invoice){
?>
<td><?php echo $invoice['Customer']['display_name']; ?></td>
<td><?php echo $invoice['Project']['project_name']; ?></td>
여기 내 컨트롤러 : 나는 송장을 인쇄 할 경우
<?php
class InvoicesController extends AppController {
public $helpers = array('Status');
public function index() {
$uid = $this->Auth->user('cloud_id');
$this->set('uid', $uid);
$allInvoices = $this->Invoice->find('all', array(
'conditions' => array(
'Invoice.cloud_id' => $this->Auth->user('cloud_id'),
)
)
);
$this->set('invoices', $allInvoices);
}
, 나는 관련 분야를 볼 수 있지만 값이 비어 있습니다. 이와 같이 :
Array
(
[Invoice] => Array
(
[id] => 143
[cloud_id] => 1
[invoice_number] => 143
[customer_id] => 2
[date] => 2013-08-17
[period] => 30
[project_id] => 1
[status] => 1
[notes] =>
[secret] => df56cd45ea7cb086458cc5c3480f77c386647a86
)
[Customer] => Array
(
[id] =>
[cloud_id] =>
[company] =>
[frontname] =>
[lastname] =>
[address] =>
그러나 모델의 외래 키를 변경하면 열이 존재하지 않는다는 오류가 발생합니다.
여기에 무슨 문제가 있습니까?
미리 감사드립니다.
컨트롤러는 어디에 있습니까? –
이러한 관계가 잘못되었습니다. 모델을 ** 조건 **과 연결하고'foreignKey'를 false로 설정해보십시오. 어떤 버전의 Cake를 사용하고 있습니까? 이전 버전은 외장형 키 이름에 대해 특별히 권장하는 DB 스키마를 사용하지 않는 한 모델 링크에 끔찍합니다. –
컨트롤러를 추가했습니다. 2.4.3을 사용하고 있습니다. – Vincent