cakephp如何将这个请求数据保存在另一个字段中
How to save cakephp this request data in another field
我创建了一个输入字段名称 money
并且有一个 select 选项。如果我 select debit
那么货币输入数据将保存在 debit_money
字段中,如果我 select credit
那么货币输入数据将保存在 credit_money
中场地。
Add.ctp 像这样
Select 字段喜欢
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
字段中没有保存数据,我也没有收到任何错误。
先看['debit_money'] == $this->request
你使用等于 Comparison operator ==
而不是 Assignment Operator =
您的代码应如下所示
$this->request->data['Transaction']['debit_money'] = $this->request->data['Transaction']['money'];
我创建了一个输入字段名称 money
并且有一个 select 选项。如果我 select debit
那么货币输入数据将保存在 debit_money
字段中,如果我 select credit
那么货币输入数据将保存在 credit_money
中场地。
Add.ctp 像这样
Select 字段喜欢
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
字段中没有保存数据,我也没有收到任何错误。
先看['debit_money'] == $this->request
你使用等于 Comparison operator ==
而不是 Assignment Operator =
您的代码应如下所示
$this->request->data['Transaction']['debit_money'] = $this->request->data['Transaction']['money'];