我在指定的框架上有一个小应用程序。我想控制应用程序失败时用户看到的内容。这不应该是标准的 Web 服务器响应,不同的浏览器会以不同的方式显示它。对此,我想使用Falcon\Debug。但是,据我了解,框架的这个组件总是会显示如下内容:
但是,只有在我的应用程序中启用了调试(例如使用环境变量)时,我才想显示此信息。在其他情况下,我只想显示一个描述错误的页面。
问题:如何实现?
最佳答案
这是我在index.php 文件中的实现:
try {
$root = str_replace('\\', '/', dirname(dirname(__FILE__))) . '/';
require_once $root . 'apps/Bootstrap.php';
$bootstrap = new Bootstrap();
$bootstrap->run();
} catch (\Exception $e) {
if (DEV_MODE === true) {
$debug = new \Phalcon\Debug();
die($debug->listen()->onUncaughtException($e));
} else {
header('HTTP/1.1 500 Internal Server Error');
// Your fancy error page for users here!
die();
}
}
这个想法是在配置文件中的某个位置有一个变量,您可以轻松地在 true/false 之间切换。
更新!
您也可以添加此内容:
if (DEV_MODE === true) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
}
关于php - Phalcon:如何使用 Phalcon\Debug,但控制开发/生产环境的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44330337/