We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

[EE 2] Sharing Libraries, or Loading Libraries from other Modules

Development and Programming

Ian Cook's avatar
Ian Cook
93 posts
16 years ago
Ian Cook's avatar Ian Cook

I’ve got a number of custom modules that use a few of the same common libraries, in particular my database class.

Is there a place I can put this commonly used class for use in modules via

$this->EE->load->library('mydb');

or, is there a way to load that class in one module when it’s located in the libraries folder of another module?

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
16 years ago
Bjørn Børresen's avatar Bjørn Børresen

wow, I was just wondering about this myself 😊

I guess one could put it in the main libraries folder, but that seems kind of hacky. A cool thing would be able to specify this->EE->load->library(libname, modulename) .. and then have a module w/common libs.

       
Ian Cook's avatar
Ian Cook
93 posts
16 years ago
Ian Cook's avatar Ian Cook

That’s what I ended up doing, created a folder off the main libraries folder to store my common stuff. I’d much prefer this was in third_party to minimize the places I need to backup when doing upgrades.

       
Bjørn Børresen's avatar
Bjørn Børresen
629 posts
16 years ago
Bjørn Børresen's avatar Bjørn Børresen

I found a way to do this ..

Create a folder called “libaries” in third_party .. this is for your common module libraries.

Libraries can then be loaded from this folder in two ways, either by specifying path directly (this will load Textile library):

$this->EE->load->library("../third_party/libraries/Textile");

.. or adding PATH_THIRD to the array of paths to check for libraries:

$this->EE->load->_ci_library_paths[] = PATH_THIRD; // in constructor                
        $this->EE->load->library("Textile");

haven’t decided yet on which I think is best.. Still feels a bit hacky since there is no official way to do this. The second way is probably only possible because of PHP4 support - if EE was made for PHP5 only that array would be private ..

       
Ian Cook's avatar
Ian Cook
93 posts
16 years ago
Ian Cook's avatar Ian Cook

awesome, thanks! i’ll probably go for the first option.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.