2011-11-23 29 views
2

我使用zend框架,我已啓用佈局。有時候一些不好的編碼控制器/動作可能會拋出一個錯誤/警告,例如:「警告:在第12行的/path/to/controllers/controllername.php中出現錯誤」。我想知道是否有單點輸出將數據返回給請求者,以便我可以在發送之前檢查發送的內容。這樣我可以使用正則表達式並從發送給請求者的最終結果中刪除php警告。如何在返回給用戶之前處理所有php數據?

回答

1

而不是嘗試重新解析輸出,您可以關閉記錄錯誤到輸出和/或更改錯誤報告級別。

您可以直接更改php.ini或使用ini_set方法。

error_reporting(0); // Reporting is off 
error_reporting(E_ALL); // Reports all 
error_reporting(E_ERROR); // Reports only errors 
error_reporting(E_ERROR | E_WARNING); // Reports errors and warnings 
ini_set("error_reporting", E_ALL); // Reporting is on 
ini_set("error_reporting", 0); // Reporting is off 

ini_set("display_errors", 0); // Turn off logging to output 
ini_set("log_errors", 1); // Turn on logging to file 
ini_set("error_log", "errors.log"); // Name of error log 
+0

更改錯誤報告級別沒有意義,你知道 –

2

當生成一個ZF項目時,它會創建一個errorcontroller,然後將其設置爲在未捕獲任何異常時使用。此控制器還附帶一個視圖,您可以在其中指定發生錯誤時要顯示的內容。

我不確定它是否使用控制器的設置,或者如果框架使用它,如果它存在,但也許在文檔中。 http://framework.zend.com/manual/en/zend.controller.exceptions.html#zend.controller.exceptions.handling

+0

非常感謝真棒的答案。 – Gean

相關問題