Autodetect environment type and load variables from
.env
togetenv()
automagically.
This is a PHP version of the original Ruby dotenv.
- Copy folder system to your codeigniter projects.
- Add this code to your codeigniter index.php before codeigniter core loaded (before this text "* LOAD THE BOOTSTRAP FILE") :
/* * -------------------------------------------------------------------- * LOAD PHP DOT ENV FILE * -------------------------------------------------------------------- * * And away we go... * */ require_once BASEPATH . 'dotenv/autoloader.php'; $dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load();
-
Create .env according your environment by copy file .env.example for database configuration and the other configuration. Example : .env.development, .env.testing, .env.production
-
Load configuration, in file application/config/database.php change to this configuration
$db['default']['hostname'] = getenv('DB_HOST');
$db['default']['username'] = getenv('DB_USERNAME');
$db['default']['password'] = getenv('DB_PASSWORD');
$db['default']['database'] = getenv('DB_DATABASE');
$db['default']['dbdriver'] = getenv('DB_CONNECTION');
- Add ".env" to your .gitignore file
- It will be running, thank you
- 0.1.1
- CHANGE: Autodetect environment & Update Readme
- 0.1.0
- Initial version
Agung Jati Kusumo – @its_agungjk – [email protected]
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/agungjk/phpdotenv-for-codeigniter
- Fork it (https://github.com/agungjk/phpdotenv-for-codeigniter/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request