ZF:在控制器中检索错误消息

时间:2011-05-06 13:05:48

标签: php zend-framework zend-form

在Zend Framework中,当我在控制器中时,如果form-> isValid()返回false,则可以检索错误消息? 我添加了带有自定义错误消息的表单元素,我不想在输入字段下面但在表单顶部显示错误消息。

此致 安德烈

1 个答案:

答案 0 :(得分:1)

是。当isValid()使用getMessages()方法失败时,您可以收到错误消息:

 if ($this->getRequest()->isPost()) {                       
     if ($yourForm->isValid($_POST)) {
        // success       
     } else {
        // isValid fails

        $errorMsgs = $yourForm->getMessages());    

        // process them, assign them to a view variable
        // and display in a view.
        // you can also create a view helper or a partial view script
        // that would handle the display of the messages.
     }
 }

如果您不希望在其下方显示错误,也可以从元素中删除“错误”修饰符。

相关问题