2011-05-06 61 views
1

在Zend Framework中,當我在控制器中時,如果form-> isValid()返回false,那麼可以檢索錯誤消息嗎? 我添加了帶有自定義錯誤消息的表單元素,並且我不想在輸入字段下但在窗體頂部顯示錯誤消息。ZF:檢索控制器中的錯誤消息

問候 安德烈

回答

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. 
    } 
} 

您也可以從您的元素中刪除「錯誤」裝飾,如果你不希望有下面這些錯誤顯示。

相關問題