Autodetect environment type and load variables from
.env
togetenv()
,$_ENV
and$_SERVER
automagically.
- Install Composer
$ curl -s http://getcomposer.org/installer | php
- Paste all of these files to your CodeIgniter root.
- Install package on
application
directory
$ cd application
$ composer install
- Enable your Composer Autoload and Hooks:
application/config/config.php
$config['enable_hooks'] = FALSE;
to $config['enable_hooks'] = TRUE;
$config['composer_autoload'] = FALSE;
to $config['composer_autoload'] = TRUE;
- Add this code to your application hooks:
application/config/hooks.php
// Use this code if your .env files on *CodeIgniter ROOT* folder
$hook['pre_system'] = function() {
$dotenv = Dotenv\Dotenv::create(FCPATH);
$dotenv->load();
};
or
// Use this code if your .env files on *application* folder
$hook['pre_system'] = function() {
$dotenv = Dotenv\Dotenv::create(APPPATH);
$dotenv->load();
};
- Create your .env files
$ cp .env.example .env
- Edit
database.php
onapplication/config/database.php
- Replace this code:
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'mysqli',
to
'hostname' => getenv('DB_HOSTNAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'database' => getenv('DB_DATABASE'),
'dbdriver' => getenv('DB_DRIVER'),
- Fork it!
- Create your feature branch (
git checkout -b my-new-feature
) - Make your changes
- Commit your changes (
git commit -am 'Add my feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request