CodeIgniter env基于MY_类扩展

I'm working on a CodeIgniter 3.1.4 project and am aware that I can use MY_ prefixed library classes to extend the system libraries.

This is great and works as expected, but I'd like to be able to determine the class being used dependant on either the current environment, or by DotEnv values (I've already got a DotEnv library working fine).

The production site uses the servers 'sendmail' to send email, I would like to be able to use MailGun (or another) in development, allowing me to overriding the 'to' value just before sending to allow for safe development utilising a production like dataset.

Much like is able to be done in Laravel where you can use .env's MAIL_DRIVER=mailgun and MAIL_TO_ADDRESS=x@y.com to force all outbound mail to one address for development.

I'm sure it must be possible, but my lack of experience with CI and where I should be implementing this into the framework is letting me down.

The answer is actually in the links that Vickel sent. You can override your configuration files per domain/environment and you can therefore change the MY_ prefix to YOUR_ prefix in the different config.php file.

How you do this (quoted but tweaked):

Create the directory application/config/not_my_environment/

Copy your existing config.php into the above directory

Edit application/config/not_my_environment/config.php so it contains your production settings

Set the ENVIRONMENT constant based on an htaccess SetEnv variable (I have just posted a very similar answer here: Maintain the same project within multiple sub-domains) which then allows you to vary your files per domain.

Once you are running off a custom per-deployment set of configuration files you can set the prefix to be whatever you like and therefore have multiple MY_, YOUR_, ANY_ prefix based classes override the CI defaults.