Welcome Guest, Not a member yet? Register   Sign In
Suggestion : SPL Autoload config
#1

(This post was last modified: 09-07-2015, 04:19 AM by djha.)

Hi,

Actually, loading a class is only possible by "CI_Loader" class.
It will be interesting to disable this feature and use "spl_autoload_register".

An option $config['spl_autoload'] with a function value (class & method) that allow to autoload your own classes.
Then you can decide the naming convention & folders hierarchy.

Possible custom naming example :

Code:
class "MY_Storage_Adapter_File" store in "MY/Storage/Adapter/File.php"
autoload : $file_path = str_replace('_', '/', $class);

That's mean PSR-0 or PSR-4 autoloading ...

M.
Reply
#2

http://www.codeigniter.com/user_guide/ge...oader.html

If you set $config['composer_autoload'] to a path to a file which registers your autoloader, CI3 will call the file in /system/core/CodeIgniter.php. Alternatively, if you just set the value to TRUE, it will attempt to find the file in APPPATH . 'vendor/autoload.php'.

While the intent of the configuration value is to register composer as an autoloader, you could configure any autoloader the same way, you just need a simple script that registers your autoloader.

As for disabling CI_Loader, that would just disable all of CI's system classes, since they don't follow the conventions required by most autoloaders.
Reply
#3

I register my autoload function in the file "vendor/autoload.php".
(previously, I used the pre_system hook).

Thanks,
M.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB