我对 CakePhp 中的相关表有一个非常简单的问题。我有两张通过关系多对多的表。
我只是想显示相关对象的名称,而不是它的 ID。
我的控制台做的界面和这个一模一样:
我在CakePhp 文档中找到了递归参数,我在 StackOverflow 上找到了许多相关问题,但仍然失败。
这是控制器:
/**
* 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>