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

Accessing custom CodeIgniter library through ExpressionEngine

Development and Programming

AirWatch's avatar
AirWatch
26 posts
14 years ago
AirWatch's avatar AirWatch

I’m not sure if this is possible, but various posts in the forums here and in the documentation suggest that I should be able to let EE know what’s going on in the CodeIgniter foundation that it’s built on.

So, in light of that, I’ve got a CI app (with a specific custom library I need), and an EE site. The /system directory is structured like this:

/system

/system/codeigniter
/system/codeigniter/application (this is my existing CI app)

/system/codeigniter/system (this is the same CI folder that EE runs from)

/system/expressionengine
... (this is the normal EE - templates, add-ons, etc.

My understanding was that I could use this setup to built an EE module that would integrate well with CI.

Currently, I have a module setup based on the EE module dev tutorial, and a method in it that does this, just as a starting point:

function __construct()
{
    $this->EE =& get_instance();
    $this->CI =& get_instance();
    $this->auth =& $this->CI->load->library('mylibrary');
}

But then it doesn’t recognize the library when I load the module (this is all happening inside the EE control panel, at this point, just so I can make a connection between the two). Says the library doesn’t exist. Is there anything I can do to make this connection, or am I going the wrong direction entirely?

Thanks, Jonathan

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi AirWatch,

It’s my understanding that the instance of CI that you are calling would be the one included with ExpressionEngine, not your application. Essentially your instance of CI isn’t being loaded because the index.php file that loads that app isn’t being called. Therefore, since your library lives in your app, and you are calling ExpressionEngine’s CI instance, the library isn’t being loaded.

We aren’t setup to provide developer related questions in the support forums, so in an effort to get you an answer, I’m going to move this into Development and Programming. The Community there might be able to shed some light on this for you.

Cheers!

       
daveganley's avatar
daveganley
3 posts
14 years ago
daveganley's avatar daveganley

I’ve not tried to use CI from EE but wouldn’t your code be like this

function __construct()
{
    $this->EE =& get_instance();
    $this->CI =& get_instance();
    $this->CI->load->library('mylibrary');

}

function method()
{
$this->CI->mylibrary->my_library_method();
}
       
Rob Sanchez's avatar
Rob Sanchez
335 posts
14 years ago
Rob Sanchez's avatar Rob Sanchez

EE and your module don’t know at all about your system/codeigniter/application folder. Try this, it might work:

$this->EE =& get_instance();
$this->EE->load->add_package_path(BASEPATH.'../application/');
$this->EE->load->library('mylibrary');
$this->EE->mylibrary->do_stuff();
       
AirWatch's avatar
AirWatch
26 posts
14 years ago
AirWatch's avatar AirWatch

@Rob, this seems like it’s in the right direction. It now loads the library from the application folder just fine, but it does throw an error (Unable to load the requested language file) about a missing language file associated with the library. I verified that the language file is present (application/language/english/).

Is this something you might be able to speak to, as well?

Many thanks.

       
Rob Sanchez's avatar
Rob Sanchez
335 posts
14 years ago
Rob Sanchez's avatar Rob Sanchez

Try doing this to load your language file from within your library:

$this->EE->lang->load('mylangfile', '', FALSE, TRUE, BASEPATH.'../application/');
       
AirWatch's avatar
AirWatch
26 posts
14 years ago
AirWatch's avatar AirWatch

That works perfectly! Thanks so much for your help; I think this gives us what we’ll need to work from.

       

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.