php - 如何判断 CakePHP 3.x 中的调试模式是否开启
问题描述
我想知道如何在 env() 函数中检索 var ...
/**
* Debug Level:
*
* Production Mode:
* false: No error messages, errors, or warnings shown.
*
* Development Mode:
* true: Errors and warnings shown.
*/
'debug' => filter_var(env('DEBUG', true), FILTER_VALIDATE_BOOLEAN),
现在我正在使用
<?php if(DEBUG == true) { ?>
但这会引发错误
Use of undefined constant DEBUG - assumed 'DEBUG' (this will throw an Error in a future version of PHP)
解决方案
As suggested by ndm you can use read
method to check whether debug mode is ON
or OFF
.
Add this in your controller
use Cake\Core\Configure;
and then use read method like this:
if (Configure::read('debug')) {
echo "Debug mode is ON";
} else {
echo "Debug mode is OFF";
}
推荐阅读
- javascript - 在组件实例中调用函数调用的语法
- c++ - 调用类中的成员函数没有匹配的函数
- .net - 为什么这两个同类型的F#类对象不相等?
- django - Django REST Framework 用户注册隐私问题:寻找最佳实践,如果具有给定电子邮件的用户已经存在,则不显示异常
- python - 将二维数组插入另一个二维数组,同时考虑值
- google-apps-script - TypeError:无法在 doGet 读取 null 的属性“getProtections”
- python - 在 Python 中使用逻辑回归进行引导 - 构建测试向量
- django - Whitenoise 似乎无助于图像出现在 heroku 中
- javascript - .push 与异步函数的问题
- nginx - nginx重新加载后返回旧数据