【问题标题】:Phalcon PHP Ajax error modelPhalcon PHP Ajax 错误模型
【发布时间】:2016-05-09 13:21:20
【问题描述】:

当我尝试像这样if( !$myModel->save() ) 保存我的模型时,如果我想获取错误消息,我必须包围 try catch 我的条件...我无法检查 save() 是否为假,因为这不会返回错误。

如何在不使用 try catch 的情况下获取$myModels->getMessages()

我想这样做example,如果保存不起作用,则返回 json_encode。

【问题讨论】:

    标签: php ajax phalcon


    【解决方案1】:

    The example from the 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!";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      • 2018-07-31
      相关资源
      最近更新 更多