GETモジュールから表示ページがもつIDを参照する
ページ情報を取得する
URLコンテキスト(参照)で表されるページ情報のうち各種IDをGETモジュール内で取得する方法を説明します。
GETモジュール内でページ情報のうち、例えばエントリーID(以下EID)を取得することができれば、そのモジュールがどのエントリーから呼び出されたかによって参照する情報を変えることができます。基本的には、Entry_BodyやEntry_Headlineなどのモジュールもそのようにページ情報を取得することで、表示すべき情報を決定しデータベースを参照しています。
スコープの設定
下記のようにプロパティを設定することで、$this->bid, $this->cid, $this->eidとして、表示中のページが持つID情報を取得できます。
public $_scope = array(
'bid' => 'global',
'cid' => 'global',
'eid' => 'global',
);表示中ページの各種IDを参照するサンプル
<?php
namespace Acms\Custom\GET;
use ACMS_GET;
class Hoge extends ACMS_GET
{
public $_scope = array(
'bid' => 'global',
'cid' => 'global',
'eid' => 'global',
);
function get()
{
$string[] = 'Global Vars';
$string[] .= "BID = $this->bid";
$string[] .= "CID = $this->cid";
$string[] .= "EID = $this->eid";
return nl2br(implode("\r\n", $string));
}
}出力結果
<!-- bid = 1, cid = 2, eid = 5 の場合 --> Global Vars<br /> BID = 1<br /> CID = 2<br /> EID = 5
取得できる情報
GETモジュールで現在表示中のページより取得できる情報には以下のものがあります。
| プロパティ | 説明 | 例 |
|---|---|---|
| bid | ブログID | http://sample.com/blog/ |
| uid | ユーザーID | http://sample.com/uid/1/profile.html |
| cid | カテゴリーID | http://sample.com/news/ |
| eid | エントリーID | http://sample.com/news/123.html |
| keyword | キーワード | http://sample.com/keyword/検索文字/ http://sample.com/?keyword=検索文字 |
| tag | タグ | http://sample.com/tags/aaa/ |
| field | フィールド | http://sample.com/field/station/あの駅/ |
| start | 検索の始まり日時 | http://sample.com/2017-01-01/-/2017-03-03/ |
| end | 検索の終わり日時 | http://sample.com/2017-01-01/-/2017-03-03/ |
| page | ページ番号 | http://sample.com/page/2/ |
| order | 並び順 | http://sample.com/order/datetime-desc/ |