我有这 3 张桌子:
顾客:
服务:
客户服务:
有了这个关系CustomerservicesTable.php
:
$this->belongsTo('Customers')
->setForeignKey('customerid');
$this->belongsTo('Services')
->setForeignKey('serviceid');
在Template\Customerservices\add.ctp
我有一个带有下拉列表和数字字段的表单:
<div class="customerservices form large-9 medium-8 columns content">
<?= $this->Form->create($customerservice) ?>
<fieldset>
<legend><?= __('Add transaction') ?></legend>
<?php
echo $this->Form->input('Transaction type',array('options' => $servicesList));
echo $this->Form->control('price');
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
在Controller\CustomerservicesController.php
:
public function add($customerid = null)
{
$customerservice = $this->Customerservices->newEntity();
if ($this->request->is('post')) {
$customerservice->customerid = $customerid;
$customerservice->serviceid = //get selection from dropdown
if ($this->Customerservices->save($customerservice)) {
$this->Flash->success(__('The customerservice has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The customerservice could not be saved. Please, try again.'));
}
$this->set(compact('customerservice'));
$servicesList = TableRegistry::getTableLocator()->get('Services')->find('list');
$this->set(compact('servicesList'));
}
如何替换评论以保存serviceid
在下拉控件中选择的内容?
(第二个问题是否可以price
根据下拉选择隐藏该字段?)