I can see two different ways of saving data to my database in CakePHP 3.x, one that works and one that doesn't. Other than the obvious, that I can't get one to work, why would you use one rather than the other, and can you tell why one of the ways isn't working for me?
Option 1: (not working)
$usersTable = TableRegistry::get('users');
$user = $usersTable->newEntity();
$user = $usersTable->patchEntity($user, $this->request->data);
$usersTable->save()
This option gives the error,
Warning (4096): Argument 1 passed to Cake\ORM\Table::save() must implement interface Cake\Datasource\EntityInterface, none given, called in
Notice (8): Undefined variable: entity [CORE\src\ORM\Table.php, line 1453]
Option 2: Does work
$user = $this->Users->newEntity();
$user = $this->Users->patchEntity($user, $this->request->data);
$this->Users->save($user)