我想更改表格用户中帐户的余额。但我想在另一个Controller而不是UsersController中执行此操作。
M代码:
public function myfunctionname() {
$this->layout = 'customer';
$this->loadModel('User');
if ($this->request->is('post')) {
// Some working stuff
$this->User->updateAll(array('balance' => 'balance - 5'), array('customerid' => $this->Session->read('Auth.User.id')));
$this->MyControllerName->create();
if ($this->MyControllerName->save($this->request->data)) {
$this->Flash->success( __('Success!'));
$this->redirect('some redirect');
} else {
$this->Flash->error( __('Error!'));
}
}
}
我会收到以下错误:
Database Error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'customerid' in 'where clause'
SQL Query: UPDATE `mydbname`.`users` AS `User` SET `User`.`balance` = balance - 5 WHERE `customerid` = '5'
谢谢!
答案 0 :(得分:1)
我明白了:
$this->User->updateAll(array('balance' => 'balance - 5'), array('id' => $this->Session->read('Auth.User.id')));