0 votes
1.3k views
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
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 1.7k views
0 votes
1 answer 12.8k views
asked Aug 19, 2016 in General by Shed
0 votes
1 answer 1.1k views
asked Oct 4, 2021 in General by Tester Testee (220 points)
0 votes
0 answers 681 views
asked Oct 4, 2021 in General by anonymous
0 votes
1 answer 1.1k views
asked Jan 23, 2022 in General by Sarath
0 votes
1 answer 1.1k views
asked Oct 29, 2021 in General by anonymous
...