1
我想知道我在這裏做錯了什麼。cakephp表關係爲空
我有這樣的關係
模型的Propriétaire:
var $belongsTo = array(
'Residence' => array(
'className' => 'Residence',
'foreignKey' => 'residence_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
住宅模型
var $hasMany = array(
'Proprietaire' => array(
'className' => 'Proprietaire',
'foreignKey' => 'residence_id',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
在我的Propriétaire試圖讓居住名字這樣
<?php
class ProprietairesController extends AppController {
var $name = 'Proprietaires';
function index() {
$this->Proprietaire->recursive = 1;
$this->set('proprietaires', $this->paginate());
$residences = $this->Proprietaire->Residence->find('list');
$this->set(compact('residences'));
}
}
?>
BU t在我的客戶視圖
<?php foreach ($proprietaires as $proprietaire): ?>
<?= print_r($proprietaire['Residence'])?>
<tr <?= $this->Cycle->css(array('list-line-odd', 'list-line-even'),true); ?>>
<td><?php echo $proprietaire['Proprietaire']['nom']; ?> </td>
<td style="text-align: center;"><?php echo $proprietaire['Proprietaire']['prenom']; ?> </td>
<td style="text-align: center;"><?php echo $proprietaire['Residence']['nom']; ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('Modifier', true), array('action' => 'edit', $proprietaire['Proprietaire']['id'])); ?>
<?php echo $this->Html->link(__('Supprimer', true), array('action' => 'delete', $proprietaire['Proprietaire']['id']), null, sprintf(__('Êtes-vous certain de vouloir supprimer # %s?', true), $proprietaire['Proprietaire']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
print_r(proprietaire ['Residence']給了我一個空數組。
Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1 Array () 1
什麼是壞?我的表關係?
感謝您的幫助。
你從'公關'($住宅)'得到什麼?還有,你看過蛋糕產生的SQL查詢嗎? – bjudson
您確定您正確設置了您的dabase表,並且表中實際存在相關的「居住」數據嗎? –