【发布时间】:2012-01-10 22:53:01
【问题描述】:
我想知道我在这里做错了什么。
我有这种关系
专有模式:
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' => ''
)
);
在业主中,我尝试获得这样的住宅名称
<?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'));
}
}
?>
但在我的老板看来
<?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
什么是坏的?我的表关系?
感谢您的帮助。
【问题讨论】:
-
你从
pr($residences)得到什么?另外,你看过蛋糕生成的 SQL 查询了吗? -
您确定您的数据库表设置正确,并且您的表中确实存在相关的“住宅”数据吗?
标签: cakephp pagination