CodeIgniter 4 tips

To prevent the debug toolbar from appearing for a certain controller method when in development mode, for example if you are generating a CSV file with code, edit app/Config/Filters.php and add the following

public function __construct()
  // hide debug toolbar when generating a CSV file
  if (strpos($_SERVER['REQUEST_URI'], 'export_csv')) unset($this->globals['after'][0]);

It isn’t obvious from the CodeIgniter 4 documentation how to prevent the debug toolbar from being added to the bottom of text output with a ResourceController.

Either output an array which changes the content type to application/json,

edit app/Config/Filters.php

public $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
        'after' => [
            // 'toolbar',
            'toolbar' => ['except' => 'feedback/*'],
            // 'honeypot',

Or use header X-Requested-With set to XMLHttpRequest in a REST client like Postman.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.