Debugging save() returning false CakePHP 3.0
Not sure if the earlier answer is based on an older version, but in the latest cakephp version (3.4) you can retrieve the errors directly from the $entity within the controller. The errors array contains each entity field that failed, with a child array of failed validations.
<?php
// In Articles Controller
...
public function add(){
...
if ($this->Articles->save($article)) {
$this->Flash->success(__('The Article has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
Log::Debug($article->errors());
}
The problem turned out to be the data, as expected but couldn't see immediately because the save was returning false and the data was quite large.
I first made a subset of the problem data which displayed the same behaviour then, following ndm's suggestion, changed the ORM/Table.php code for the save function as follows to be able to see where the problem was:
// $entity->errors() is deprecated as of CakePHP 3.7
// $entity->getErrors() should be used in later versions
$x = $entity->errors();
if ($x) {
debug($entity);
debug($x);
return false;
}
So that I could see what was going on and went on to fix the data.