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

https://docs.phalconphp.com/en/latest/reference/models.html#creating-updating-records

<?php

$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 530 views
0 votes
1 answer 5.9k views
asked Aug 19, 2016 in General by Shed
0 votes
1 answer 1.9k views
0 votes
2 answers 3.8k views
+1 vote
1 answer 918 views
+2 votes
1 answer 499 views
asked Feb 8, 2017 in General by Marc Lentin
...