lpa Posted May 14, 2013 Share Posted May 14, 2013 Why couldn't I use this in a template: if ($user->name == 'admin') { $config->debug = true; } or if ($user->isSuperuser()) { $config->debug = true; } 1 Link to comment Share on other sites More sharing options...
Wanze Posted May 14, 2013 Share Posted May 14, 2013 What is the purpose of doing this? It should work, but depends where in the template you call this snippet. Link to comment Share on other sites More sharing options...
lpa Posted May 14, 2013 Author Share Posted May 14, 2013 I could enable debugging on production site for superusers only. If I change config.php $config->debug = true, then it is global for the whole site. Link to comment Share on other sites More sharing options...
alan Posted May 14, 2013 Share Posted May 14, 2013 If that works then it looks like a great idea, better than this probably Link to comment Share on other sites More sharing options...
Soma Posted May 14, 2013 Share Posted May 14, 2013 It's not possible or doesn't do anything in a template because PW needs the config to be loaded at the very start, and at the time a template is rendered it's maybe already too late. Also it won't enable it in the backend, which you probably want. Why not directly in the config.php.? Well, you also can't use $user in the config.php itself, since it's too early and $user isn't yet there when loaded by PW index.php. So the best option (if I'm not missing something) would be a autoload module and put that code in the init function. public function init() { if($this->user->hasRole('superuser')){ $this->config->debug = maybe; } else { $this->config->debug = false; } } If you put that in HelloWorld.module's init it will work fine and load at the beginning when the API becomes available. Edit: somewhere along these lines if not completely mistaken. 2 Link to comment Share on other sites More sharing options...
Soma Posted May 14, 2013 Share Posted May 14, 2013 All you can do in the site/config.php is something like you can get from PHP: $config->debug = false; if(isset($_GET['debug'])) $config->debug = true; So you could add /?debug to a url and have debug mode on. Or you could add this to the top in admin.php template in site/templates/ folder if($user->name == 'admin') $config->debug = true; And have debug mode only for admin only in admin. 2 Link to comment Share on other sites More sharing options...
lpa Posted May 15, 2013 Author Share Posted May 15, 2013 Thanks Soma for this answer! Link to comment Share on other sites More sharing options...
ryan Posted May 17, 2013 Share Posted May 17, 2013 For security, I'd avoid implementing solutions that would let anyone enable debug mode. So GET vars aren't ideal unless you can get enough "security by obscurity" with the GET variable (perhaps by name or value). My IP address doesn't change often, so I usually enable debug mode directly from my /site/config.php with a line like this: $config->debug = $_SERVER['REMOTE_ADDR'] === '123.123.123.123'; 1 Link to comment Share on other sites More sharing options...
adrian Posted February 22, 2017 Share Posted February 22, 2017 I know this is ancient, but I wanted to note that if this worked in the past, it no longer works. I think I recently even saw reference to placing $config->debug = true in ready.php. None of these options work properly. If you want conditional debug mode, you need to use the debugif option: https://github.com/processwire/processwire/blob/35df716082b779de0e53a3fcf7996403c49c9f8a/wire/config.php#L56-L71 Keep in mind that setting it to true in a module or ready.php etc might make it look like it's working because the "Debug Mode Tools" link and icon will appear in the admin, but it will not output any errors/notices/warnings to the browser. Also, in the debug panel you'll notice that the "Database Queries", "Timers", and "Autoload" sections are not populated because they require debug mode to be on Also, of course, with Tracy enabled you don't really need debug mode on (or if you do have it on), it will take care of capturing any errors, and hiding them from users, anyway. The only thing you will be missing with it off, are those "Database Queries", "Timers", and "Autoload" sections.* Anyway, hope that helps to avoid any confusion for those who come here in the future. * This really wasn't meant to be a Tracy advert, but thought it was relevant because it solves the reason why you would want debug mode on only for superusers or the like. 4 Link to comment Share on other sites More sharing options...
szabesz Posted February 22, 2017 Share Posted February 22, 2017 Thanks for the notes! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now