あらゆるアドバイスをお寄せいただきありがとうございます。
次のように配列が作成されるファイル(コンテンツファイル)が1つあります。
$config['plugins']['BannerRotate'] = array(
'container' => 'abroadView',
'arrows' => true,
'auto' => true,
'speed' => '15000',
'width' => '300px',
'height' => '220px',
'tags' => 'slider'
);
これは、いわゆる「テンプレート システム」によって取得され、ページ (およびその配列) を引数 (かなり標準) としてレイアウトがレンダリングされます。
その配列は、次のように新しいオブジェクトを生成するためにテンプレート システムによって使用されます。
if(isset($GLOBALS['config']['plugins'])){
foreach($GLOBALS['config']['plugins'] as $plugin => $ary){
$$plugin = new Ispweb_Plugindaemon(CURRENTSRV,getcwd().'/',
$GLOBALS['config']['plugins'][$plugin],$plugin);
// this statement is simply the result of the eval statement below
}
}
では、この場合のプラグインの名前は BannerRotate なので、オブジェクトは $BannerRotate (可変変数) です。これを行っているのは、ページごとに複数のプラグイン オブジェクトを持つことができるようにするためです。このオブジェクトは、メンバー関数 $BannerRotate->getJS() を使用して jQuery プラグインを呼び出すために使用されます。これらのメンバー関数呼び出しは、テンプレート システム内にあります (重要)。
初期配列 [OUTSIDE THE TEMPLATING SYSTEM] (最初にオブジェクトを作成するためにバッファリングしているファイル) と同じファイル内でメンバー関数を呼び出すと、すべてが停止します。var_dump($BannerRotate) を実行すると完全なオブジェクトが得られるため、これは意味がありません。ただし、そのコンテンツ ファイルで $BannerRotate->printNoscript() を実行すると、すべてが消え、オブジェクトは作成されません。次に、非オブジェクトのメンバー関数を呼び出しているという致命的なエラーが発生します。それが問題だ。
コンテンツ ファイルをバッファリングする (そしてオブジェクトを作成する) ためにテンプレート システム内で行っていることは次のとおりです。
ob_start();
include $core_page_content; // the content file (where initial array is)
if(isset($GLOBALS['config']['plugins'])){
foreach($GLOBALS['config']['plugins'] as $plugin => $ary){
$ins[] = $plugin;
}
}
$t = ob_get_contents();
ob_end_clean();
foreach($ins as $in){
$a = CURRENTSRV; // a,b,c,d are just making the eval statement more clean
$b = getcwd().'/';
$c = array();
foreach($GLOBALS['config']['plugins'][$in] as $key => $value){
$c[$key] = $value;
}
$d = $in;
eval("\$$in = new Ispweb_Plugindaemon(\"$a\",\"$b\",\$c,\"$d\");");
echo $$in;
}
include $core_page_content;
$page_content = ob_get_contents();
ob_end_clean();
同じファイル内でメンバー関数の1つを呼び出さない限り、オブジェクトにアクセスできる理由を誰かが知っていますか?
私に何ができる?
PS私はセットアップが理想的ではないことを知っています. それについて私にできることは何もありません。
ありがとう!
TL;DRファイルBの変数を使用して、ファイルAにオブジェクトを作成しています.ファイルBをバッファリングして、ファイルAにフィードするパラメータを取得し、オブジェクトを作成し、それを別のバッファに出力し、そのバッファにファイルBを含めます同じように。ファイル B に、おそらく作成されたオブジェクトへの関数呼び出しがある場合、致命的なエラーが発生します。非オブジェクトのメンバー関数への呼び出しです。
その他の注意事項:
ファイル B:
$config['plugins']['BannerRotate'] = array(
'container' => 'abroadView',
'arrows' => true
);
// page content (XHTML)
ファイル A:
ob_start();
$core_page_content = 'file_b';
include $core_page_content;
if(isset($config['plugins'])){
foreach($config['plugins'] as $plugin => $ary){
$ins[] = $plugin;
}
ob_end_clean();
foreach($ins as $in){
$$in = new Ispweb_Plugindaemon(CURRENTSRV,getcwd().'/',$config['plugins'][$in],$in);
}
include $core_page_content;
$page_content = ob_get_contents();
ob_end_clean();
// later on in the file
include 'top.htm';
include $page_content;
include 'bot.htm';