Created
March 10, 2011 10:35
-
-
Save ahomu/863904 to your computer and use it in GitHub Desktop.
[a-blog cms] loadEntryFieldとbuildFieldメソッドのつかいかた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
loadEntryField関数は,カスタムフィールドをFieldオブジェクトとして返します | |
buildFieldメソッドは,Fieldオブジェクトを自動で展開します | |
これで展開すると,<!-- BEGIN key:touch -->のようなブロックや, | |
{selected:key#var}みたいな変数が自動でループ内につくれます. | |
*/ | |
require_once ACMS_LIB_DIR.'GET.php'; | |
class ACMS_GET_Sample extends ACMS_GET | |
{ | |
function get() | |
{ | |
$Tpl = new Template($this->tpl, new ACMS_Corrector()); | |
// エントリーを取得して | |
$DB = DB::singleton(dsn()); | |
$SQL = SQL::newSelect('entry'); | |
$all = $DB->query($SQL->get(dsn()), 'all'); | |
// foreachで回す | |
foreach ( $all as $row ) { | |
$title = $row['entry_title']; | |
$datetime = $row['entry_datetime']; | |
$eid = $row['entry_id']; | |
// loop内の変数用に連想配列をつくる | |
$vars = array( | |
'title' => $title, | |
'datetime' => $datetime, | |
'url' => acmsLink(array('eid'=>$eid)) | |
); | |
// eidを与えると,カスタムフィールドが Fieldオブジェクトという形で返ります | |
/** | |
* loadEntryField | |
* | |
* @param int|string $eid entry_id | |
* @return Field | |
*/ | |
$Field = loadEntryField($eid); | |
// buildFieldメソッドというのを使って,返り値を変数用の連想配列とマージします | |
// 興味があったらbuildFieldの返り値をvar_dumpしてみてください | |
/** | |
* buildField | |
* | |
* @param Field $fields loadEntryFieldで得たFieldオブジェクト | |
* @param Template $Tpl Templateクラスのインスタンス | |
* @param string $block 展開先のブロック名 | |
* @return array | |
*/ | |
$fds = $this->buildField($Field, $Tpl, 'entry:loop'); | |
$vars = array_merge($fds, $vars); | |
// ループを追加します | |
$Tpl->add('entry:loop', $vars); | |
} | |
return $Tpl->get(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment