lonnieezell / Bonfire

Jumpstart your CodeIgniter web applications with a modular, HMVC-ready, backend.
http://cibonfire.com
1.39k stars 524 forks source link

System Event triggered module error: Unable to load the requested language file. #1172

Open jbalatero opened 9 years ago

jbalatero commented 9 years ago

System event after_create_user triggered members module and an error occured: Unable to load the requested language file 'members' for current language 'english' AND for fallback to 'English'.

The constructor is good and the language file members_lang.php also exist in members module.

public function __construct(){
       ...
        $this->lang->load('members');
       ...
}

Reason: members_lang.php is being loaded on event caller Users module even though members_lang does not exist on users module but on members module. BF_Lang.php#load() gets the module by fetching from the url.

Temporary fix: Specify the module on lang load.

public function __construct(){
       ...
        $this->lang->load('members/members');
       ...
}

My suggested right fix for this is to specify the module on lang load during generation of module to avoid this kind of error in the future.

mwhitneysdsu commented 9 years ago

Note that this will happen with almost any type of file loaded from a module when called from another module, not just language files. So, if a particular class is used to handle events or is intended to be called via Modules::Run(), it's a good idea to specify the module name when using the loader in the class' constructor and any methods which might be used this way.

It may be worth investigating whether events are especially prone to this because the library doesn't utilize the Modules library to load the class/file, but I'm not sure how much of an issue it would be to change the way the Events library loads event subscribers, either.

I was also considering the possibility of updating this functionality to use The PHP League's Event package, but that requires investigating compatibility of events (or feasibility of creating an adapter) as well as the possibility of using it in a Composer-free environment.

lonnieezell commented 9 years ago

As an FYI - Sprint's Events solution is a simplified version of the Leagues. As in, it provides almost all of the same functionality with only a single file...