Skip to content

fix Dotenv\Dotenv loading #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 21 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
Expand All @@ -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
Expand All @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion application/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": {
"vlucas/phpdotenv": "^3.3"
"vlucas/phpdotenv": "^5.6"
}
}