2

I'm developing a module and an extension and I'm having trouble accessing the custom libraries that I placed inside the "libraries" folder of my module directory.

I've been trying to link to them inside public functions like this:

    $this->EE=& get_instance();
    //  Instantiate class to access Litmus  
    $this->EE->load->library('litmus');

In the case above the filename is "litmus.php" and the class name used is "Litmus".

I've also tried putting the same code in the constructor function to no avail.

Thanks in advance for any help on this.

EDIT: ANSWER

All of the comments were helpful and this is what wound up working:

function Litmusee()
{
    // Make a local reference to the ExpressionEngine super object
    $this->EE =& get_instance();
    $this->EE->load->add_package_path(PATH_THIRD.'litmusee/');
    $this->EE->load->library('litmus_lib');
    $this->lib = $this->EE->litmus_lib;
}

When calling a function:

        // Create a new Litmus test
       $clients = $this->lib->get_litmus_email_clients();

With this setup I don't believe the library name matters.

2
  • Are you trying to access the library from the module or the Extension? Not sure it makes a difference, but worth exploring...! Aug 4, 2013 at 14:34
  • Both...just got the module working and posting edit to show answer.
    – jsuissa
    Aug 5, 2013 at 0:19

3 Answers 3

3

The code you have should work fine. I've just run a test on a module and it loads fine in EE v2.5.3 (either in a method or in the class constructor). I've just had a quick read of the EE changelog and can't see any reference to changes there, so don't think it's version related.

Are you sure it's not calling the Class and then doing something unexpected?

I notice the Structure module has a capital letter for the filename (matching the library class name), but Store module doesn't, but does have the class name in front of it. But neither of these I think is relevant.

Have you tried dropping a var_dump("TEST"); in your litmus construct?

Are you targeting the library methods correctly after loading?

$this->EE = & get_instance();
$this->EE->load->library('import');
$this->EE->import->process();

Not sure if it's relevant, but ensure you repeat the EE instance declaration in the library also $this->EE = & get_instance();.

In your module do you have:

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', true);

Set to display errors?

One final thing to check - do you have any other conflicts of class names using "litmus"?

I've had problems in the past with libraries being used by both Extension and module (hence my comment to your question) and got conflicts, possibly that's what is occurring. To avoid it I loaded it in the normal way:

//###   Loaded using this method due to multiple classes and extension classes also loading it   ###
if (!class_exists('Settings'))
    require_once(PATH_THIRD.'cart/libraries/settings.php');
//$this->EE->load->library('settings'); <- not working :(
$this->settings = new settings();

Note: this was only because of conflicts in class already declared, as in the same class I load other libraries using the EE method.

1

Not, positive, but I believe the library needs to have the module name in front of it. i.e. Mymodulename_litmus.php then call

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

This will tell EE to look in your addon's libraries folder and not EE's stock library folder. (I think).

0
1

In some instances you have to add the addon's path as a package path to the loader:

$this->EE =& get_instance();
$this->EE->load->add_package_path(PATH_THIRD.'your_addon_name/');
$this->EE->load->library('litmus');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.