Webコンサルタントの愚痴とアジャイル,生産性向上,Trac,オープンソースなどの与太話
簡単すぎる。rootアカウントで
結果、以下のように表示されれば良い。
こちらも簡単だ。以下にサンプルソースを丸ごと掲載しておく。pager_sample.php
require_once("DB.php");
require_once("Pager/Pager.php");
require_once("Smarty/Smarty.class.php");
//データベースからデータを取得する
$datasource = "pgsql://postgres:@localhost/bugtracker";
$db = DB::connect($datasource );
$sql = "select * from mantis_bug_text_table order by id asc;";
$res = $db->query($sql);
//データベースから取得したデータを配列に入れる
while ($row = $res->fetchRow( DB_FETCHMODE_ASSOC )) {
$data_list[] = array(
"id"=>$row["id"],
"description"=>$row["description"]
);
}
//データベース後処理
$res->free();
$db->disconnect();
//Pagerへのデータ割り当て処理
$perPage=10;
$params=array("perPage"=>$perPage, "itemData"=>$data_list);
$o_page=Pager::factory($params);
foreach($o_page->getPageData() as $item){
$data_list_for_page[]=$item;
}
//Smartyへの割付処理
$smarty=new Smarty;
$smarty->template_dir = "./templates";
$smarty->compile_dir = "./templates_c";
$smarty->cache_dir = "./cache";
$smarty->assign("list", $data_list_for_page);
$navi=$o_page->getLinks();
$smarty->assign("pageNavi", $navi['all']);
$smarty->display("pager_sample.tpl");
?>
簡単な流れであるが、
Smartyのテンプレートも簡単だ。pager_sample.tpl
以上で完了だ。細かい処理は省いているが適宜追加すれば良い。
なお、今回のサンプルではデータベースにバグトラッキングシステムのmantisのテーブルを使った。
ミルキーぱぱ 2007/09/13
大変参考になりました。ありがとうございました。
Ryuzee 2007/09/14
>ミルキーぱぱさん
どういたしまして。
昔のブログの移行で醜いままだったので、ソースなどハイライト表示に変えました。
さかい 2008/08/17
大変参考にさせて頂きました。
ありがとうございました!