Jef*_*rts 2 php cakephp cakephp-3.0 cakephp-3.6
我想知道如何检索 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),
Run Code Online (Sandbox Code Playgroud)
现在我正在使用
<?php if(DEBUG == true) { ?>
Run Code Online (Sandbox Code Playgroud)
但这会引发错误
Use of undefined constant DEBUG - assumed 'DEBUG' (this will throw an Error in a future version of PHP)
Run Code Online (Sandbox Code Playgroud)
根据 ndm 的建议,您可以使用readmethod 来检查调试模式是ON还是OFF.
将此添加到您的控制器中
use Cake\Core\Configure;
Run Code Online (Sandbox Code Playgroud)
然后使用这样的读取方法:
if (Configure::read('debug')) {
echo "Debug mode is ON";
} else {
echo "Debug mode is OFF";
}
Run Code Online (Sandbox Code Playgroud)