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]);
}

CodeIgniter 4 Array in Config with .env file

The .env file can use dot syntax to represent associative arrays but the documentation is poor, here is how I did it.

Create a new class in the Config directory e.g. Salesforce.php

 '',
		'account2' => ''
	];
	public $campaigns = [
		'campaign1' => '',
		'campaign2' => ''
	];
}

Add lines to the .env file

salesforce.accounts.account1 = 'config('Salesforce');';
salesforce.accounts.account2 = '00123451HKB';
salesforce.campaigns.campaign1 = '1234000000dBAEvA';
salesforce.campaigns.campaign2 = '1234000000dBAEvB';

Finally to access within your controller

$salesforce = config('Salesforce');
echo $salesforce['account1']; // displays 00123451HKB
echo $salesforce['campaign2']; // displays 1234000000dBAEvB

Advantages: You commit can commit the files in the Config folder to version control without them storing sensitive information while the sensitive data stays in the .env file and is unique to a particular environment.

SEO and image file names

Surprisingly it looks like even the filename of an image used in a website has SEO benefit – see supporting links below – this may be a pain but a multilingual site should consider duplicating images in order to use different filenames containing keywords in each of the languages a site uses.

Supporting Links:

Sublime Text – British dictionary for spelling

If you want a British English dictionary in Sublime Text 3 for spell checking, choose Preferences / Settings and add the following line:

"dictionary": "Packages/Language - English/en_GB.dic"

The Grid – Launch

I’m excited that my founder membership of The Grid has just been enabled. I’ve only spent a short time using it so far but it’s making WordPress feel ancient. The Grid uses AI to design the site according to the content and changes that design with time.

https://thegrid.ai/willis-owen