简体   繁体   English

Phalcon PHP Ajax错误模型

[英]Phalcon PHP Ajax error model

When i'm trying to save my model like this if( !$myModel->save() ) I have to surround in try catch my condition if I want to get the errors messages... I can't check if the save() is false, because this will not returns the errors. 当我试图像这样保存我的模型if( !$myModel->save() ) ,如果我想获取错误消息,我必须包围if( !$myModel->save() )我的状况...我无法检查是否保存()为假,因为这不会返回错误。

How can I do to get $myModels->getMessages() without using try catch ? 如何不使用try catch获得$myModels->getMessages()

I want to do like this example and return json_encode if the save doesn't work. 我想像这个例子一样 ,如果保存不起作用,则返回json_encode。

The example from the docs , shows you how to get the messages after you save your $myModel docs中的示例 ,向您展示了保存$myModel之后如何获取消息

$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";
    // get the messages of the saved Robot.
    foreach ($robot->getMessages() as $message) {
        echo $message, "\n";
    }
} else {
    echo "Great, a new robot was saved successfully!";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM