1

我正在尝试将外部库加载到 ExpressionEngine 插件中,但得到:

消息:未定义属性:Detector::$EE

在插件本身中,我有:

public function __construct()
{
    $this->EE->load->library('detector');
    $this->EE =& get_instance();
}

我的文件夹设置如下:

检测器
-libraries
--Detector.php
-pi.detector.php

我究竟做错了什么?

经过加载库错误后,我现在收到带有以下代码的“未定义变量”错误:

public function detector()
{
 return $ua->ua;
}

public function user_agent()
{
return $ua->ua;
}

那就是如果我的模板中有 {exp:detector:user_agent} 。如果我 {exp:detector} 我没有输出。

4

1 回答 1

7

你应该像这样改变你的代码:

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

先初始化$this->EE变量,然后就可以加载库了。所以在这种情况下

$this->EE->detector->user_agent();
于 2012-10-22T07:12:00.793 回答