2

我想知道如何在 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)
4

2 回答 2

7

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";
}

Cakephp -> Configuration -> Reading Configuration Data

于 2018-11-29T12:06:27.607 回答
0

通过Configure::read(key)您可以了解。

请检查以下链接:

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

于 2018-12-02T13:32:05.847 回答