weixin_33695450 2016-05-09 13:21 采纳率: 0%
浏览 22

Phalcon PHP Ajax错误模型

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.

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条回答 默认 最新

  • weixin_33701251 2016-05-09 16:21
    关注

    The example from the docs, shows you how to get the messages after you save your $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: 
    ";
        // get the messages of the saved Robot.
        foreach ($robot->getMessages() as $message) {
            echo $message, "
    ";
        }
    } else {
        echo "Great, a new robot was saved successfully!";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊