Welcome Guest, Not a member yet? Register   Sign In
Class DotEnv and Autoload

Hello everyone,

I started using CodeIgniter lately in version 3. I am self taught and had never used a framework before. By cons I tested 7 different and Codeigniter in his V3 is the one that was closest to my style of coding. The version 4 is a total redesign, I fully understand that we must be in the style of the day but I have a little trouble anyway ... In short.

I want to make a .env file load relative to where the application is located: production, testing, development. I have tried multiple way to load a class in app/config which normally is in the logic that must load the files in the folder automatically. Something that does not happen while I respect the namespace. There, I did as in the documentation with a class implements so to make a personal class ... It does not load. So here is the test code:
<?php namespace Config;

use CodeIgniter\Config\DotEnv;

class Env implements DotEnv
     * The directory where the .env file can be located.
     * @var string
    protected $path;


     * Builds the path to our file.
     * @param string $path
     * @param string $file
    public function __construct(string $path, string $file = '.env_development')
        $this->path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;


Here I want the file that loads to be the one for the development. I made the tests from the original file with if conditions, it works great. By cons when I make sure to make my own class in the app/Config folder, nothing happens because no automatic loading. I even try to make mistakes and nothing happens (logical because it automatically goes into production). Can you enlighten me on this point, especially on the operation of autoload, because even by doing individually with $classmap, nothing happens.

Looking forward to reading you,

PS: Sorry for my english

OK, your autoload not work ^^ ...
If rename app/Config/Events.php to Events1.php... This file is not loaded.

Something does not work, I already make use of the spl_autoload_register, it is clear that it works super well. But here he only loads things apparently called ... He does not do automatism. Or I missed something, anyway I read the doc several times, do different tests ... In short, I dry ...

The only way I found it is to edit directly in bootstrap. I do not like to do that, hope to have an answer one day.

Theme © iAndrew 2016 - Forum software by © MyBB