1
votes

I am trying to save an item through my model, but saving fails.

When I output validationErrors - I get empty array, so no validation problems seem to be available. What could be failing my save()?

function resave($wid, $kTime){
    $this->contain();
    $word = $this->getById($wid);
    // Successfully tretrieved here
    $word['ModelName']['column'] = $kTime;
    if($this->save($word)){
        return 'success';
    }else{
        // this returns empty array
        return $this->validationErrors;
    }
}
2

2 Answers

2
votes

To save yourself some time in the future, if a save() isn't working, the first place to look is in your SQL log and errors.

You should try installing Debug Kit Toolbar for CakePHP (https://github.com/cakephp/debug_kit). It makes it easy to view your SQL log, along with a bunch of other useful stuff. Or, alternatively, you can just put this in your layout file to view SQL history/errors:

<?php echo $this->element('sql_dump'); ?>
1
votes

It was a problem with float and array type. I investigated it with gettype() and figured it out.