Inserting Records in CakePHP 3 and CakePHP 4: The Subtle Differences

Inserting Records in CakePHP 3 vs 4

Note the difference in newEntity for CakePHP and newEmptyEntity for CakePHP4

CakePHP4:

$review = $this->Reviews->newEmptyEntity();
$review = $this->Reviews->patchEntity($review, $datatosve);
​$this->Reviews->save($review);

 

CakePHP3:

$review = $this->Reviews->newEntity();
$re = $this->Reviews->patchEntity($review, $datatosve);

if ($this->Reviews->save($re)) {
   $this->Flash->success(__('Saved.'));
​}

 

 

Share this Post