【EC-CUBE】あれ?同じページが、ダブって出力されているよ?
EC-CUBE(2.13.2)の商品リストの処理を書き替えたくて
親クラス(html/data/class/pages/products/LC_Page_Products_List.php)
を継承している、
子クラス(html/data/class_extends/page_extends/products/LC_Page_Products_List_Ex.php)
に親クラスの中身をまるごと移植したら
ページが二重にダブって表示されてた。なんでだ。
解説
原因
そもそも親子でまったく同じコードにしていたのが間違いだった。
LC_Page_Products_List_Ex.php
<?php /** * Page のプロセス. * * @return void */ public function process() { parent::process(); $this->action(); $this->sendResponse(); }
ページ表示処理(sendResponseメソッド)が親と子それぞれのクラスで1回ずつ、
計2回実行されていたせいでダブって表示されてたらしい。
LC_Page_Products_List_Ex.php
<?php parent::process(); //←親クラスのprocess()メソッドを実行 (ページ表示処理 1回目) $this->action(); $this->sendResponse(); //←子クラスのsendResponse処理メソッド (ページ表示処理 2回目)
対処
親クラスの処理だけで十分だったので、子クラスの2行をコメントアウトして解決。
LC_Page_Products_List_Ex.php
<?php /** * Page のプロセス. * * @return void */ public function process() { parent::process(); // $this->action(); // $this->sendResponse(); }
蛇足
試しにsendResponse処理メソッドだけいっぱい実行してみた。
LC_Page_Products_List_Ex.php
<?php /** * Page のプロセス. * * @return void */ public function process() { parent::process(); // $this->action(); $this->sendResponse(); $this->sendResponse(); $this->sendResponse(); $this->sendResponse(); $this->sendResponse(); }
結果
面白い。書いた分だけ出てきました。
…でも実際のサイトでは、こんな表示欲しくないのでほんとに蛇足ですね。