1

外部ライブラリを ExpressionEngine プラグインにロードしようとしていますが、次のようになります。

メッセージ: 未定義のプロパティ: 検出器::$EE

プラグイン自体には、次のものがあります。

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

私のフォルダは次のように設定されています:

検出器- ライブラリ
--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 に答える