diff --git a/README.md b/README.md index 5f50c5c..a93e54f 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ -# PHP DotEnv for CodeIgniter -> Autodetect environment type and load variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically. +# PHP DotEnv for CodeIgniter 3.2.x +> Autodetect environment type and load variables from `.env`, `$_ENV` and `$_SERVER` automagically. ![](cover.png) - - - ## Installation 1. Install Composer ``` @@ -21,45 +18,37 @@ $ composer install ``` - - - ## Configuration 1. 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;` +1. Add this code on index.php : `/index.php` -2. Add this code to your application hooks: `application/config/hooks.php` +beefore `require_once BASEPATH.'core/CodeIgniter.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(); -}; +require_once __DIR__ . '/vendor/autoload.php'; +$dotenv = Dotenv\Dotenv::createImmutable(__DIR__); +$dotenv->load(); + +/* + * -------------------------------------------------------------------- + * LOAD THE BOOTSTRAP FILE + * -------------------------------------------------------------------- + * + * And away we go... + */ ``` -3. Create your *.env* files +1. Create your *.env* files ``` $ cp .env.example .env ``` - - ## Usage Example ### Database Configuration @@ -75,18 +64,14 @@ $ cp .env.example .env to ``` - 'hostname' => getenv('DB_HOSTNAME'), - 'username' => getenv('DB_USERNAME'), - 'password' => getenv('DB_PASSWORD'), - 'database' => getenv('DB_DATABASE'), - 'dbdriver' => getenv('DB_DRIVER'), + 'hostname' => $_ENV['DB_HOSTNAME'], + 'username' => $_ENV['DB_USERNAME'], + 'password' => $_ENV['DB_PASSWORD'], + 'database' => $_ENV['DB_DATABASE'], + 'dbdriver' => $_ENV['DB_DRIVER'], ``` - - - - ## Contributing 1. Fork it! 2. Create your feature branch (`git checkout -b my-new-feature`) diff --git a/application/composer.json b/application/composer.json index 170aedf..d7c6bb7 100644 --- a/application/composer.json +++ b/application/composer.json @@ -1,5 +1,5 @@ { "require": { - "vlucas/phpdotenv": "^3.3" + "vlucas/phpdotenv": "^5.6" } }