繁体   English   中英

如何判断CakePHP 3.x中是否打开了调试模式

[英]How to tell if debug mode is on in 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)

根据ndm的建议,您可以使用read方法来检查调试模式是ON还是OFF

将此添加到您的控制器中

use Cake\Core\Configure;

然后使用如下所示的读取方法:

if (Configure::read('debug')) {
  echo "Debug mode is ON";
 } else {
  echo "Debug mode is OFF";
}

Cakephp->配置->读取配置数据

通过Configure::read(key)可以找出答案。

请检查以下链接:

https://book.cakephp.org/3.0/en/development/configuration.html#reading-configuration-data

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM