0

enter image description here

I am trying to update multiple fields with function updateAll() in Cakephp version 4, but I have a error.

I leave the catch of the error and the code of my controller Users.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • You've tried to call a non-static function in a static way (`Table::updateAll`). That's not how that function works. You need to tell it *what* table to update. Your second call, `$actualizar->updateAll(...)` looks like it could work, but you'd need `$actualizar` to be a table object (like from `TableRegistry::getTableLocator()->get('NameOfTable')`). – Greg Schmidt Jul 14 '20 at 22:41
  • Does this answer your question? [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Greg Schmidt Jul 14 '20 at 22:42
  • Hi Chris, and tried what you are saying and it sends me exactly the same error, surely it is that I am still doing something wrong, could you be a little more specific please, the truth is that I have little with cakephp, I thank you in advance for a new comment, thank you. – alextorres Jul 15 '20 at 14:29
  • What table are you trying to access? Specifically, we need the name of the table class, from `src/Model/Table`, which accesses the underlying database table in question. That table name then goes in place of "NameOfTable" in `$actualizar = \Cake\ORM\TableRegistry::getTableLocator()->get('NameOfTable')`, immediately before you try to do `$actualizar->updateAll(...)`. – Greg Schmidt Jul 15 '20 at 16:39
  • Thanks for your answer Greg, the model is User, I need to update several fields into the table users from controller users. I know it is a bit strange, but I must update the fields of a different user than the one logged in. I appreciate your comments. Thanks – alextorres Jul 15 '20 at 18:06
  • If you're updating the users table from within the users controller, then `$this->Users` should already be the table you need. So just `$this->Users->updateAll(['sa' => ....` should work. – Greg Schmidt Jul 15 '20 at 18:35

0 Answers0