我想更改我的表用户中的帐户余额。但我想在另一个 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'
谢谢!
最佳答案
我明白了:
$this->User->updateAll(array('balance' => 'balance - 5'), array('id' => $this->Session->read('Auth.User.id')));
关于php - CakePHP 2.8.4 : Change User balance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42811044/