gpt4 book ai didi

php - Phalcon : How to use Phalcon\Debug, but control the output for development/production environment?

转载 作者:行者123 更新时间:2023-12-03 07:41:55 27 4
gpt4 key购买 nike

我在指定的框架上有一个小型应用程序。如果我的应用程序失败,我想控制用户看到的内容。这不应是标准的Web服务器响应,不同的浏览器会以不同的方式显示该响应。在这方面,我想使用Falcon \ Debug。但是,据我了解,框架的这一部分将始终显示如下内容:

enter image description here

但是,我只想在应用程序中启用调试时(例如,使用环境变量)显示此信息。在其他情况下,我只想显示一个描述错误的页面。

问题:如何实现?

最佳答案

这是我在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 : How to use Phalcon\Debug, but control the output for development/production environment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44330337/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com