【发布时间】:2011-07-16 11:31:52
【问题描述】:
我的应用中有两个表格:“客户”和“约会”
在约会表中,我有一个名为“clientid”的外键,它将表链接在一起。我将如何显示该用户的约会?
例如,在查看客户 /admin/clients/view/201/ 时,我会看到客户 201 的客户详细信息以及该客户的约会。
到目前为止,我的控制器如下所示:
class ClientsController extends AppController
{
var $name = 'Clients';
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow(array('*'));
}
function admin_view($id = null)
{
$this->Client->id = $id;
$this->set('client', $this->Client->read());
}
任何帮助将不胜感激。谢谢
编辑:客户端模型
class Client extends AppModel
{
var $name = 'Client';
var $useTable = 'clients';
}
Edit2:查看
<h1><?php echo $client['Client']['lastname']; ?> <?php echo $client['Client']['firstname']; ?> (<?php echo $this->Html->link('Edit', array('action' => 'edit', $client['Client']['id'])); ?>)</h1>
<p><strong>Date of Birth:</strong> <?php echo $client['Client']['dateofbirth']; ?></p>
<h3>Appointments</h3>
<table>
<?php foreach ($appointments as $appointment): ?>
<tr>
<td>
<?php echo $this->Html->link($appointment['Appointment']['date'],
array('admin' => true, 'controller' => 'appointment', 'action' => 'view', $appointment['Appointment']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
【问题讨论】: