PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, December 31, 2021

[FIXED] Debugging save() returning false CakePHP 3.0

 December 31, 2021     cakephp, cakephp-3.0, debugging, save     No comments   

Issue

I have some code which has broken somewhere along the way and I'm having trouble debugging it.

This is a simplified version of it.

$data = $this->request->data;

$form = $this->Forms->get($data['id'], [
    'contain' => ['FieldsForms' => ['data']
    ]
]);

$form = $this->Forms->patchEntity($form, $data,
    ['associated' => [
        'FieldsForms.Data',

    ]
]);

if ($this->Forms->save($form)) {
    // sunshine and rainbows
} else {
    // wailing and gnashing of teeth
}

I'm left wailing and gnashing teeth without any errors, as far as I can see if I debug the $data it looks like it's ok (though since it's fairly long and contains a bunch of UUIDs it's possible I'm missing something).

Validation errors is empty.

The save is returning false - any suggestions on how to debug this might save what sanity I have left.

Thanks!


Solution

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.



Answered By - Rich Hobbs
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing