0 votes
asked in Phalcon by

When I try to save my model like if( !$myModel->save() )

I have to surround in try catch my condition if I want to get the errors messages...

I can't seem to check if the save() is false, because this will not return the errors.

How can I do to get $myModels->getMessages() without using try catch ?

I want to do like this example and return json_encode if the save doesn't work.

1 Answer

0 votes
answered by



$robot       = new Robots();
$robot->type = "mechanical";
$robot->name = "Astro Boy";
$robot->year = 1952;

if ($robot->save() == false) {
    echo "Umh, We can't store robots right now: \n";
    foreach ($robot->getMessages() as $message) {
        echo $message, "\n";
} else {
    echo "Great, a new robot was saved successfully!";

Related questions

0 votes
1 answer 555 views
0 votes
1 answer 10.2k views
asked Aug 19, 2016 in General by Shed
0 votes
1 answer 5.7k views
0 votes
2 answers 8.4k views
+1 vote
1 answer 1k views
+2 votes
1 answer 543 views
asked Feb 9, 2017 in General by Marc Lentin