phpdotenv ( .env ) в CodeIgniter 3.0 с использованием хуков

application/config/config.php
$config['composer_autoload'] = true;


{
    "require": {
        "vlucas/phpdotenv": "^2.2"
    }
}


application/config/hooks.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files.  Please see the user guide for info:
|
|	http://codeigniter.com/user_guide/general/hooks.html
|
*/
$hook['pre_system'] = function() {
    $dotenv = new Dotenv\Dotenv(APPPATH);
    $dotenv->load();
};
/* End of file hooks.php */
/* Location: ./application/config/hooks.php */

Создаем файл .env


DB_HOST="localhost"
DB_USER="root"
DB_PASS="admin123"

используем
getenv() или $_ENV

Взято с roopampoddar.com/2016/01/26/integrating-phpdotenv-env-files-in-codeigniter-3-0-using-hooks/
  • 0

Нет комментариев