CodeIgniter icon indicating copy to clipboard operation
CodeIgniter copied to clipboard

Loading extended helper from package

Open davidbehler opened this issue 14 years ago • 5 comments

I'm running 2 apps on the same server and they share the system folder and a folder called "common" where I put custom/new libraries they share and I did not want to put in both app folders. I can do this using the packages autoload option and it works just fine. Now I got a extended helper that they both share as well and that's where it all fails :)

According to the user guide if I want to extend a helper I should just create a new file in my application/helper folder with the same name as the original file and then just prepend it with the subclass suffix, in my case the god old 'MY_'. I did exactly this but instead of putting it in my application/helpers folder, I put the file in common/helpers (my shared package folder for both apps), but the helper just wasn't loaded.

So I had a look at the code and in the system/core/Loader.php on line 502-523 it only checks the application folder for a file with the subclass prefix but not the package folder(s). It's the same for libraries, the Loader only checks for extended libraries in the application folder and only loads new libraries (those that don't exist in the system folder or overwrite those) from the package folder.

So loading extended anything from a package is not possible, only libraries/helpers that overwrite existing ones or are completely new can be loaded from packages. I guess that's because the subclass prefix can be changed to whatever you want and if you prefix your packaged files with 'YOUR_' and then someone tries to use your package but has their prefix set to 'MY_' it won't work at all.

Do you see a way of solving this?

davidbehler avatar Dec 13 '11 15:12 davidbehler

What version of CI are you using? Haven't tested it, but in 2.1 this looks to be handled properly.

narfbg avatar Jan 11 '12 00:01 narfbg

2.1.0 :)

It's been a while since I looked into this and I'll investigate some more in the next few days and maybe I'll try to fix it myself and make a pull request.

davidbehler avatar Jan 11 '12 00:01 davidbehler

It's not possible yet, indeed. Seems like a major issue in Loader, which makes the package useless when it comes to extending the core.

dmmihaylov avatar Feb 04 '12 10:02 dmmihaylov

I'm having the same issue. Is there any plans to change this behaviour without hacking/extending CI_Loader ?

nbourguig avatar May 04 '12 15:05 nbourguig

Fixed, see the above commit.

narfbg avatar Nov 12 '12 11:11 narfbg