Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

save() works from time to time

HI I have a small issue about saving new characters in my game online. There is piece of code:

$newOne = new Characters();
$newOne->exhaustion = 12600;
...
if($newOne->save()) {
...
}

And with the same input and data given to this code it works from time to time. I mean I can click Create button and nothing will happen but I click this same another time and it works perfectly. I can refresh the site few times (no pattern) and it work too. How can I check why it happens and mostly, why it doesn't work all the time?

Kamil

I presume when you click the button it sends an XmlHttpRequest to the server. First of all, you should check the output of that request in the browser's debug bar (on chrome: F12 -> Network tab).

Check $newOne->getMessages() and php logs.

No @lajosbencz, it's simple, regular form and it redirects after clicking button to other page which is validation. @jurigag I can't do that because $newOne->getMessages() have some error messages after wrong execution, but in my case save() doesn't event execute and if you add some code after this line it doesn't execute too.

$newOne->save();
echo 'test';

It doesn't show "test".

edited 13d ago

Then check php logs because there is exception or seg fault.



1.1k
Accepted
answer
edited 13d ago

Ok. So where can I find this log file with php errors? I have Linux Mint 18 apache2 and php7.0. You mentioned about php logs in php and apache itself, right? I have seen some phalcon's debugging to file process here, so I ask to be sure.

EDIT. Ok, maybe code doesn't display any errors but it doesn't mean that it's not working. I've debugged it by this code:

try {
    // Phalcon/PHP code
} catch(\Exception $e) {
    echo get_class($e), ": ", $e->getMessage(), "\n";
    echo " File=", $e->getFile(), "\n";
    echo " Line=", $e->getLine(), "\n";
    echo $e->getTraceAsString();
}