我创建了一个输入字段名money
,并且有一个选择选项。如果我选择debit
,则资金输入数据将保存在debit_money
字段中,如果我选择credit
,则资金输入数据将保存在credit_money
字段中。
像这样添加.ctp
选择
字段echo $this->Form->input('transaction_type', array(
'empty' => 'Choose A Transaction Type',
'options' => array('Debit', 'Creadit')
));
汇款领域
echo $this->Form->input('money',array('class'=>'form-control'));
在控制器中我写了下面的代码
if($this->request->data['Transaction']['transaction_type']==0)
{
$this->request->data['Transaction']['debit_money'] == $this->request->data['Transaction']['money'];
if ($this->Transaction->save($this->request->data)) {
$this->Session->setFlash(__('The transaction has been saved.'));
}
}
此处debit_money
字段中没有数据保存,也没有出现任何错误。
答案 0 :(得分:2)
首先看一下['debit_money'] == $this->request
您使用等于Comparison operator ==
而不是Assignment Operator =
您的代码应如下所示
$this->request->data['Transaction']['debit_money'] = $this->request->data['Transaction']['money'];