0 votes
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



$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 689 views
0 votes
1 answer 11.8k views
asked Aug 19, 2016 in General by Shed
0 votes
1 answer 12 views
0 votes
1 answer 7.7k views
0 votes
2 answers 10.2k views
+1 vote
1 answer 1.2k views