所以说我想只保存2与特定交易领域我的系统*基本上我从库存股票”CakePHP的2.X:在saveField()使用变量
public function admin_take($id = null) {
if (!$this->Inventory->exists($id)) {
throw new NotFoundException(__('Invalid inventory item'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->request->data['Inventory']['amount_taken'] < $this->Inventory['Inventory']['amount']){
amt = $this->request->data['Inventory']['amount_taken'];
$this->Inventory['Inventory']['amount'] = $this->Inventory['Inventory']['amount'] - amt;
$this->Inventory['Inventory']['amount_taken'] = $this->Inventory['Inventory']['amount_taken'] + amt;
$this->Inventory->saveField('amount_taken','x');
$this->Inventory->saveField('amount','y');
$this->Session->setFlash(__('The inventory item has been saved.'));
return $this->redirect(array('action' => 'index'));
}
else if ($this->request->data['Inventory']['amount_taken'] > $this->Inventory['Inventory']['amount']) {
$this->Session->setFlash(__('request could not be processed, not enough inventory stock to fulfil request .'));
}
else {
$this->Session->setFlash(__('The request could not be processed, please try again.'));
}
}
}
else {
$options = array('conditions' => array('Inventory.' . $this->Inventory->primaryKey => $id));
$this->request->data = $this->Inventory->find('first', $options);
}
}
是取出物品有可能用包含上面算术运算中更改数据的变量替换saveField中的x和Y吗?
大多数我看到的示例倾向于在saveField $ stringValue中使用实际字符串,如果我确实需要字符串?我会去用字符串替换这里?
Dave的答案是正确的,但我挑这也为要去回合专门只更新表中的字段了一把更有效的方式。谢谢先生 – 2014-11-28 17:45:24