CodeIgniter Forums
Is there a way to turn off the debugbar for a specific controller/route - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Is there a way to turn off the debugbar for a specific controller/route (/showthread.php?tid=74788)



Is there a way to turn off the debugbar for a specific controller/route - crazyR - 11-06-2019

As the title says, im seeking a way to disable the debugbar for specific controllers/routes.

Thank you.


RE: Is there a way to turn off the debugbar for a specific controller/route - InsiteFX - 11-06-2019

The debugbar only shows in development mode if you change to production it
will not show.


RE: Is there a way to turn off the debugbar for a specific controller/route - crazyR - 11-06-2019

Thank you InsiteFX, I know this already, but that doesnt help during development Smile

I've came up with a solution, I've basically placed the following code in the Config/Boot/development.php file just above the CI_DEBUG definition:

PHP Code:
if (!empty($_SERVER['REQUEST_URI']) && substr($_SERVER['REQUEST_URI'], 0) === "/css/")
{
    define('CI_DEBUG'0);



Not sure if it is the best way, but it works.


RE: Is there a way to turn off the debugbar for a specific controller/route - kilishan - 11-06-2019

Hey crazyR - the Toolbar is attached via controller filter, so you can change the way it's specified to exclude certain uri's there. See the filters docs for more info.


RE: Is there a way to turn off the debugbar for a specific controller/route - crazyR - 11-06-2019

Thank you kilishan, That is exactly what I was looking for Smile

I did brush pass that documentation earlier but for some reason I must not have been paying enough attention to realize its importance.

Thanks again.


RE: Is there a way to turn off the debugbar for a specific controller/route - John_Betong - 11-06-2019

@crazyR
> As the title says, im seeking a way to disable the debugbar for specific controllers/routes.

I am not sure of the order that CI_DEBUG is called but I prefer defining the debug boolean constant in index.php.

You could try a conditional grouping of the /Controller/config/routes.php -> $route1 = "route"; and the debug constant will be contained in the same file.


RE: Is there a way to turn off the debugbar for a specific controller/route - tibszabo - 02-25-2021

(11-06-2019, 07:43 AM)crazyR Wrote: As the title says, im seeking a way to disable the debugbar for specific controllers/routes.

Thank you.

For me, this is working:

before showing the view create a session var:

PHP Code:
session()->set('skip_debug',true); 

then in the app\Config\Toolbar.php create a constructor then remove the View::class if that var is present.

PHP Code:
public function __construct() {
        parent::__construct();
        
        
if (session()->get('skip_debug') === true) {
            session()->remove('skip_debug');
            array_splice($this->collectors,array_search(Views::class,$this->collectors),1);
        }
    



RE: Is there a way to turn off the debugbar for a specific controller/route - Muzikant - 03-03-2025

Simplest and cleanest solution based on Filters - Except for a Few URIs documentation (working on CI 4.6.0).

In Filters.php, move 'toolbar' from $required['after'] to $globals['after'] and add 'except' with desired relative URI to it as in the example below.

app/Config/Filters.php
PHP Code:
// ...

public array $required = [
    'before' => [
        'forcehttps',
        'pagecache',
    ],
    'after' => [
        'pagecache',
        'performance',
        // 'toolbar',  // COMMENT THIS LINE
    ],
];

public array 
$globals = [
    'before' => [
        // 'honeypot',
        // 'csrf',
        // 'invalidchars',
    ],
    'after' => [
        // 'honeypot',
        // 'secureheaders',
        'toolbar' => ['except' => 'relative_uri/*'], // ADD THIS LINE
    ],
];

// ... 

You can add one URI as a string, or multiple URIs as an array of strings.

PHP Code:
'toolbar' => ['except' => 'relative_uri/*'], 

PHP Code:
'toolbar' => ['except' => ['relative_uri/*''another_relative_uri/*']],