Debug Toolbar in Codeigniter 4 not working

19.5k views Asked by At

I installed Codeigniter 4.0.2 and did following changes:

1- CI_ENVIRONMENT = development in .env file

2- SetEnv CI_ENVIRONMENT development in .htaccess in public folder

3- Added $useKint = true; in main index.php file in public folder

When I open at localhost, welcome page is rendered but no Debug Toolbar is rendered. Am I missing anything?

17

There are 17 answers

3
MicroWise On BEST ANSWER

This fixed it for me:

  1. Rename env file to .env and open it
  2. Uncomment line # CI_ENVIRONMENT = production and change to the value to development
  3. Change the app.baseURL value to your app's base URL (this seems like the step you missed)
2
Thiru A P On

The debug toolbar will be there in bottom right cornor with a codigniter code logo

  1. Click that in order to open the debug bar.

enter image description here

Click the icon you will be able to see debug bar like this. enter image description here

0
ViLar On

Here are some stuffs you can check with a fresh CI4 installation :

  • Your environment is really on development (you can check it in the footer of your welcome page). If not, be sure to set CI_ENVIRONMENT = development in your .env. Watch out because fresh CI4 doesn't come with a .env file but with a env file. Be sure to rename it.

footer of welcome page

  • Make sure you have defined('CI_DEBUG') || define('CI_DEBUG', 1); in your app/Config/Boot/development.php file

  • Try to launch your app with the command line php spark serve so you can grab some informations about your app accessing the toolbar.

http info about toolbar

  • Make sure you have a variable named $globals in app/Config/Filters.php with 'toolbar' as a value of the 'after' key and 'toolbar' being correctly mapped with the toolbar class into $aliases

    
        public $aliases = [
                'csrf'     => \CodeIgniter\Filters\CSRF::class,
                'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
                'honeypot' => \CodeIgniter\Filters\Honeypot::class
            ];
    
    
    
        public $globals = [
                'before' => [
                    //'honeypot'
                    // 'csrf',
                ],
                'after'  => [
                    'toolbar',
                    //'honeypot'
                ],
            ];
    
    

It can be some starting points, hope this helps.

0
Flavio Suárez On

Today I've faced the same issue in my very first attempt to use CI4 (with XAMPP)... The only one change I've made on the CI4 framework was to rename the env file to .env and then I set CI_ENVIRONMENT = development in .env file

I've found 2 solutions:

  • Use the "php spark serve" command to start my project instead of XAMPP

  • Point $baseURL in app\Config\App.php to my project's public folder

Hope this helps! Best regards

0
Dum On

Set the base url properly if you are not using PHP's built-in server

app/config/App.php

public $baseURL = 'http://localhost/path_to_CI/public';
0
Christian Hernandez On

You need to "php spark serve" as the documentation say, because debugbar looks for localhost:8080 as in spark set on.

0
Van Hudson Galvoso On

Make sure to use HTTP protocol and not HTTPS.

On .env file check the app.baseURL = 'http://localhost/'
and not app.baseURL = 'https://localhost'.

Then, on the browser access it using http:// and not https://.

0
Peternak Kode Channel On

I got this problem too for 3 days. Today I solve this problem by make /writable/debugbar/ to 777 (just for development)

chmod -R 777 [yourappname]/writable/debugbar/

hopefully this gives you and everyone solution

0
Juan Gabriel Machuca On

In my case, the problem was in app.baseURL I did put where my proyect is compbase

-- app.baseURL = 'http://compbase'

and I changed it to

-- app.baseURL = 'http://compbase.test'

When you are using laragon

0
Frank Ramos On

in your env file must modify the baseurl with public folder
app.baseURL = 'http://localhost/your-app/public'

0
TarangP On

Just add following lines to app/config/filters.php and its work like a charm

public $collectors = [
    \CodeIgniter\Debug\Toolbar\Collectors\Timers::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Database::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Logs::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Views::class,
     \CodeIgniter\Debug\Toolbar\Collectors\Cache::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Files::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Routes::class,
    \CodeIgniter\Debug\Toolbar\Collectors\Events::class,
];

No need of do anything else as per Document

0
erick On

Check your code at App\Config\Filtes.php.

Use this line of code:

public $aliases = [
        'csrf'     => CSRF::class,
        'toolbar'  => DebugToolbar::class,
        'honeypot' => Honeypot::class,
    ];

Instead of this:

public $aliases = [
      'csrf'     => CodeIgniter\Filters\CSRF::class,
      'toolbar'  => CodeIgniter\Filters\DebugToolbar::class,
      'honeypot' => CodeIgniter\Filters\Honeypot::class,
    ];
0
Joynal Abedin On

I was same issue with installing ci 4.1.5 and solved by this way:

make user .env file exist in project root folder.

rename env to .env or create .env in project root folder.

set development environment in .env file

CI_ENVIRONMENT=development

set base url in .env file

app.baseURL = 'http://localhost/project-root/public/'
0
Jay On

I had the same problem It solved when I change directory "writeable/debugbar" to 777 (writeable)

CodeIgniter Debut icon will show at to bottom right if if correct.

0
cdsaenz On

It's working fine here in CI 4.2.6 and a heavily modified folder structure, writable folder set as 775, on a public address too (so no need for spark serve). My issue was that $baseURL was pointing to the address with http:// instead of https:// for a typo, so the Chrome inspector helped me out to track it down.

Changing that in App.php, it works like a charm.

0
Warco On

I've set app.baseURL = 'http://localhost/project-root/public/' but used http://127.0.0.1/project-root/public/ on my browser URL -> No toolbar. Change URL to http://localhost/project-root/public/ and toolbar appears

0
lalu On

In your .env file, update the following variables

CI_ENVIRONMENT = development

app.baseURL = 'http://localhost/<name of your project>/'

app.forceGlobalSecureRequests = false

Make sure your project is running in port 8080