2

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)
Jeffrey L. Roberts
  • 2,844
  • 5
  • 34
  • 69
  • see this article https://stackoverflow.com/questions/9462231/turn-on-off-the-debug-mode-for-particular-controller-in-cakephp – Gufran Hasan Nov 29 '18 at 08:32
  • That is for creating your own debug variable, I want to use the one CakePHP provides... I don't need two debug variables, that could get messy – Jeffrey L. Roberts Nov 29 '18 at 08:50
  • 2
    `\Cake\Core\Configure::read('debug')` – ndm Nov 29 '18 at 09:20
  • ndm: There isn't a constant that has the debug value in it is there? – Jeffrey L. Roberts Nov 29 '18 at 09:25
  • No, there isn't, changing debug mode at runtime is often required in the testing environment, and a constant wouldn't allow that. If you'd like to use a constant, then you'd have to define one yourself. – ndm Nov 29 '18 at 10:41

2 Answers2

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

Sehdev
  • 5,486
  • 3
  • 11
  • 34
0

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