我在CakePhp中有一个非常简单的问题。我有两张桌子,有很多很多关系。在Cakephp中显示相关表中的字段
我只是想显示相关对象的名称,而不是它的ID。
我由控制台制造接口是完全一样的,因为这一个:
我发现递归参数在CakePhp docs,我发现很多相关的问题在计算器上,可是还是失败了。
这里是控制器:
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
$this->Application->id = $id;
if (!$this->Application->exists()) {
throw new NotFoundException(__('Invalid application'));
}
$this->set('application', $this->Application->read(null, $id));
}
这里是图。
<div class="related">
<h3><?php echo __('Related Application Memberships'); ?></h3>
<?php if (!empty($application['ApplicationMembership'])): ?>
<table cellpadding = "0" cellspacing = "0">
<tr>
<th><?php echo __('Id'); ?></th>
<th><?php echo __('Chantier Id'); ?></th>
<th><?php echo __('Application Id'); ?></th>
<th><?php echo __('Ponderation'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<?php
$i = 0;
foreach ($application['ApplicationMembership'] as $applicationMembership): ?>
<tr>
<td><?php echo $applicationMembership['id']; ?></td>
<td><?php echo $applicationMembership['chantier_id']; ?></td>
<td><?php echo $applicationMembership['application_id']; ?></td>
<td><?php echo $applicationMembership['ponderation']; ?></td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('controller' => 'application_memberships', 'action' => 'view', $applicationMembership['id'])); ?>
<?php echo $this->Html->link(__('Edit'), array('controller' => 'application_memberships', 'action' => 'edit', $applicationMembership['id'])); ?>
<?php echo $this->Form->postLink(__('Delete'), array('controller' => 'application_memberships', 'action' => 'delete', $applicationMembership['id']), null, __('Are you sure you want to delete # %s?', $applicationMembership['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
如果你已经正确设置你的协会(我还没有读到博客文章),所有你需要的信息将是'application'阵列英寸 您可以快速查看您在视图/控制器中使用'debug($ application);'查看的数据。发布你的结构(如果它是很多,使用[pastebin](http://www.pastebin.com)) – Ross 2012-07-17 13:31:13
我得到的信息存储在桥表中,所以在sql一个连接,我需要两个。正如你所看到的,包含联络人信息的模型被称为EnjeuxMembership。 – 2012-07-17 13:36:16
这是debug()信息:http://pastebin.com/qHE0kthk – 2012-07-17 13:44:58