SOY Shopで作成したサイトを表示する2
前回はSOY Shopのサイトの表示でアドレスバーにあるURLからページを取得するところまで説明しました。
ページを取得した後から表示までを説明します。
※今回の内容も下記の内容の詳細になります。
/soyshop/webapp/src/base/SOYShopSiteController.class.phpの88行目付近
$page = $dao->getByUri($uri);
$pageをダンプすると
object(SOYShop_Page)#17 (9) {
["id":"SOYShop_Page":private]=>
string(1) "3"
["name":"SOYShop_Page":private]=>
string(12) "商品詳細"
["uri":"SOYShop_Page":private]=>
string(11) "item/detail"
["type":"SOYShop_Page":private]=>
string(6) "detail"
["template":"SOYShop_Page":private]=>
string(12) "default.html"
["config":"SOYShop_Page":private]=>
NULL
["object":"SOYShop_Page":private]=>
NULL
["createDate":"SOYShop_Page":private]=>
string(10) "1394013725"
["updateDate":"SOYShop_Page":private]=>
string(10) "1394013725"
}
$pageにはデータベースから取得したSOYShop_Pageのオブジェクトが格納されています。
101行目付近の
$webPage = $page->getWebPageObject($args); $webPage->setArguments($args);
getWebPageObject関数は
/soyshop/webapp/src/domain/site/SOYShop_Page.class.phpの303行目付近にあり、
function getWebPageObject($args){
include(SOYSHOP_SITE_DIRECTORY . ".page/" . $this->getCustomClassFileName());
$obj = SOY2HTMLFactory::createInstance($this->getCustomClassName(), array(
"arguments" => array("page" => $this, "arguments" => $args)
));
return $obj;
}
サイトディレクトリのページ毎に用意されているPHPファイルをインクルードし、ページ毎のオブジェクトを取得します。
$webPageをダンプしてみると、
object(item_detail_page)#7 (33) {
["item":"SOYShop_DetailPageBase":private]=>
NULL
["nextItem":"SOYShop_DetailPageBase":private]=>
NULL
["prevItem":"SOYShop_DetailPageBase":private]=>
NULL
["currentIndex":"SOYShop_DetailPageBase":private]=>
int(1)
["totalItemCount":"SOYShop_DetailPageBase":private]=>
int(0)
["pageObject":"SOYShopPageBase":private]=>
object(SOYShop_Page)#17 (9) {
["id":"SOYShop_Page":private]=>
string(1) "3"
["name":"SOYShop_Page":private]=>
string(12) "商品詳細"
["uri":"SOYShop_Page":private]=>
string(11) "item/detail"
["type":"SOYShop_Page":private]=>
string(6) "detail"
["template":"SOYShop_Page":private]=>
string(12) "default.html"
["config":"SOYShop_Page":private]=>
NULL
["object":"SOYShop_Page":private]=>
NULL
["createDate":"SOYShop_Page":private]=>
string(10) "1394013725"
["updateDate":"SOYShop_Page":private]=>
string(10) "1394013725"
}
["arguments":"SOYShopPageBase":private]=>
array(1) {
[0]=>
string(13) "item-001.html"
}
["_soy2_content":protected]=>
string {取得したページのHTMLが入ってる}
//以下略
}
上記のように開きたいページの値が格納されていることが分かります。
SOYShopPlugin::load("soyshop.site.onload");
SOYShopPlugin::invoke("soyshop.site.onload", array("page" => $webPage));
soyshop.site.onloadの拡張ポイントの実行以後の処理は
/soyshop/webapp/src/base/site/pages/以下のページオブジェクトの種類に応じて変わります。
今回は商品詳細ページを読み込んでいるので、
/soyshop/webapp/src/base/site/pages/SOYShop_DetailPage.class.phpを見ていきます。
(ページベースのクラスに関数がない場合は親クラスである/soyshop/webapp/src/base/site/SOYShopPageBase.class.phpのSOYShopPageBaseクラスの関数を実行します)
$webPage->build($args);を見ると
SOYShop_DetailPageBase.class.php
function build($args){
$page = $this->getPageObject();
$obj = $page->getPageObject();
$alias = implode("/", $args);
try{
$itemDAO = SOY2DAOFactory::create("shop.SOYShop_ItemDAO");
$item = $itemDAO->getByAlias($alias);
//途中省略
//keywords
$keywords = $item->getAttribute("keywords");
if(strlen($keywords)) $this->getHeadElement()->insertMeta("keywords", $keywords . ",");
//description
$description = $item->getAttribute("description");
if(strlen($description)) $this->getHeadElement()->insertMeta("description", $description . " ");
}catch(Exception $e){
echo "error";
exit;
}
//item
$this->createAdd("item", "SOYShop_ItemListComponent", array(
"list" => array($item),
"obj" => $obj,
"soy2prefix" => "block"
));
}
SOYShopSiteControllerの最初の方に$argsに入れた商品URLを元に商品情報入りの商品詳細ページを組み立てていきます。
最後に/soyshop/webapp/src/base/site/classes/SOYShop_ItemListComponent.class.phpを読み込み、block:id="item"やブロックで囲った箇所にcms:id="item_name"といったSOY Shop用のタグを使えるようにしています。
(SOYShop_ItemListComponentで/soyshop/webapp/src/module/site/common/output_item.phpを読み込むことで各種cms:idを使えるようにしている)
SOYShopSiteControllerの方に戻って、main、common_executeの処理で<head>内のHTMLを置換した後、
SOYShopPlugin::load("soyshop.site.beforeoutput");
SOYShopPlugin::invoke("soyshop.site.beforeoutput", array("page" => $webPage));
soyshop.site.beforeoutputの拡張ポイントの処理を行う。
ob_start();
$webPage->display();
$html = ob_get_contents();
ob_end_clean();
//省略
/* EVENT onOutput */
SOYShopPlugin::load("soyshop.site.onoutput");
$delegate = SOYShopPlugin::invoke("soyshop.site.onoutput", array("html" => $html));
$html = $delegate->getHtml();
echo $html;
displayで設定した文字コードに変換した後、soyshop.site.output、HTMLの出力という順に処理し、
最後にecho $html;でページを表示します。
以上がアドレスバーにURLを打ち込んでから表示されるまでの流れです。
2014.03.28 | Comments(0) | Trackback(0)
トラックバック -