0

catalog/controller/mycontroller.phpの には、次のようなスクリプトがあります。

$this->data['settings'] = $this->config->get('my_module');  // retrieves data from "setting" table
foreach ($this->data['settings'] as $data) {
    if ($data['pageurl'] == 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']) {
        $this->render();
    }
}

ではExtensions > Modules、さまざまなページ URL をさまざまな URL に設定できる拡張機能をインストールしました。次LayoutsPositionsようにします。

Page URL                   Layout    Position
================================================
http://...?product_id=10   Product   Content Top
http://...?product_id=20   Product   Content Top
http://...                 Home      Content Top

私の問題は、上記のスクリプトの条件を満たす特定のページで一度だけテンプレートをレンダリングしたいということです。現在起こっていることは、とに$this->render()基づいてテンプレートを複数回表示することです。たとえば、ページにアクセスすると、テンプレートが 2 回表示されますが、コントローラーでの条件のみを満たしているため、テンプレートは 1 回だけ表示されるはずです。これどうやってするの?PositionLayoutExtensions > Moduleshttp://...?product_id=10product_id=10

4

1 に答える 1

0

First of all, do this:

var_dump('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

I guess You may be missing also the $_SERVER['QUERY_STRING'] part...

to see, what URL are You building to compare to URLs You are setting in the backend...

Next, please, do not call $this->render() in a loop no matter why the condition succeed more times, instead of this do something like this:

$this->data['settings'] = $this->config->get('my_module');  // retrieves data from "setting" table
$render = false;
foreach ($this->data['settings'] as $data) {
    if ($data['pageurl'] == HTTP_SERVER . $_SERVER['REQUEST_URI']) { // use defined constant HTTP_SERVER
        $render = true;
    }
}

if($render) {
    $this->render();
}
于 2013-06-12T08:45:01.573 に答える