我有以下3张桌子:
客户:
服务:
客户服务:
在CustomerservicesTable.php
中具有这种关系:
$this->belongsTo('Customers')
->setForeignKey('customerid');
$this->belongsTo('Services')
->setForeignKey('serviceid');
在Customers
编辑页面中,我想添加一个联合表,其中包含特定客户的Services
和customerservices
表的创建日期。
所以在Template\Customers\edit.ctp
中,我有此表:
<h3><?= __('Transactions') ?></h3>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('Date') ?></th>
<th scope="col"><?= $this->Paginator->sort('Transaction') ?></th>
<th scope="col"><?= $this->Paginator->sort('Price') ?></th>
<th scope="col" class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($services as $service): ?>
<tr>
<td><?= h($service->...................) ?></td>
<td><?= h($service->title) ?></td>
<td><?= $this->Number->format($service->price) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller'=>'customerservices','action' => 'view', $service->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller'=>'customerservices','action' => 'edit', $service->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller'=>'customerservices','action' => 'delete', $service->id], ['confirm' => __('Are you sure you want to delete # {0}?', $customer->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
,并且在edit
的{{1}}函数中,添加了以下几行:
Controller\CustomersController.php
我如何修改它以显示customerservice->在日期字段中为特定客户创建的日期?
我在使用//Get customerservices for specific customer
$servicesTable = TableRegistry::get('Services');
$services = $this->paginate($servicesTable->find()->matching('Customerservices', function(\Cake\ORM\Query $q) use ($id) {
return $q->where(['Customerservices.customerid' => $id]);
}), ['scope' =>'services']);
$this->set(compact('services'));
函数之后添加了创建日期的列,并删除了bake
的内容,是否足以访问此新列值?