Reputation: 1711
I'm trying to load an external library into an ExpressionEngine plugin but am getting:
Message: Undefined property: Detector::$EE
In the plugin itself I've got:
public function __construct()
{
$this->EE->load->library('detector');
$this->EE =& get_instance();
}
and my folders are set up like:
detector
-libraries
--Detector.php
-pi.detector.php
What am I doing wrong?
Having moved past the loading library error, I'm now getting an 'undefined variable' error with the following code:
public function detector()
{
return $ua->ua;
}
public function user_agent()
{
return $ua->ua;
}
That's if I have {exp:detector:user_agent} in my template. If I {exp:detector} I get no output.
Upvotes: 1
Views: 1417
Reputation: 449
you should change your code like this:
$this->EE =& get_instance();
$this->EE->load->add_package_path(PATH_THIRD.'/detector');
$this->EE->load->library('detector');
First initialize the $this->EE
variable, then you can load the library. So in this case it would be
$this->EE->detector->user_agent();
Upvotes: 7