私はCakePHP 3.xのデータベースにデータを保存するには2通りの方法がありますが、動作するものとそうでないものがあります。明白なこと以外に、私は働かせることができません、なぜあなたは他のものよりむしろ1つを使用するでしょうか?そして、方法の1つが私のために働いていない理由を伝えることができますか?cakephpにデータを保存する相違点
オプション1:(動作しない)
$usersTable = TableRegistry::get('users');
$user = $usersTable->newEntity();
$user = $usersTable->patchEntity($user, $this->request->data);
$usersTable->save()
このオプションは、エラーを与え、
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]
はオプション2:
$user = $this->Users->newEntity();
$user = $this->Users->patchEntity($user, $this->request->data);
$this->Users->save($user)
必須の引数を省略することは、もちろん有効ではありません。 – ndm