У меня есть 3 таблицы:
клиенты:
![enter image description here](https://i.stack.imgur.com/hYkTQ.png)
услуги:
![enter image description here](https://i.stack.imgur.com/Najgx.png)
обслуживание клиентов:
![enter image description here](https://i.stack.imgur.com/FRnMo.png)
При таком соотношении 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
функции Controller\CustomersController.php
я добавил следующие строки:
//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'));
Как я могу изменить его, чтобы показать customerservice-> datecreated в поле даты для конкретногоcustomer?
Я добавил столбец datecreated после того, как использовал функцию bake
, и удалил содержимое app\tmp\cache\
, достаточно ли этого для доступа к значениям этого нового столбца?