简体   繁体   中英

How to tell if debug mode is on in CakePHP 3.x

I want to know how I can retrieve the var inside of the env() function...

/**
 * 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),

Right now I am using

<?php if(DEBUG == true) { ?>

but that is throwing an error

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

Cakephp -> Configuration -> Reading Configuration Data

By Configure::read(key) you can find out.

Please check following link:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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