戻る      ①MySmarty.class.php      ②schedule.php     

《PHP言語 /①MySmarty.class.php》

<?php
require_once("DB.php");
require_once("Smarty/libs/Smarty.class.php");
class MySmarty extends Smarty {
private $_db;
public function __construct() {
$this->Smarty();
$this->template_dir="./templates";
$this->compile_dir="./templates_c";
$this->cache_dir="./cache";
$this->caching=FALSE;
$this->security=TRUE;
$this->_db=DB::connect("sqlite://localhost/schedule.sqlite");
}
public function __destruct() {
$this->_db->disconnect();
}
public function get_db() {return $this->_db;}
}
?>


《PHP言語 /②schedule.php》

<?php
require_once("MySmarty.class.php");
$o_smarty=new MySmarty();
$db=$o_smarty->get_db();
$stt=$db->prepare("SELECT * FROM schedule ORDER BY s_date,s_time");
$rs=$db->execute($stt);
$arySche=array();
while($row=$rs->fetchRow(DB_FETCHMODE_ASSOC)){
$data[]=array('sid'=>$row['sid'],'title'=>$row['title'],
's_date'=>$row['s_date'],'s_time'=>$row['s_time'],
'memo'=>$row['memo']);
}
$db->disconnect();
$o_smarty->assign("sches",$data);
$o_smarty->display("schedule.tpl");
?>


《PHP言語 /schedule.sqlite》


《PHP言語 /\templates\schedule.tpl》

<html>
<head>
<title>簡易スケジュール帳</title>
</head>
<body>
<h1 style="background:#cccccc">簡易スケジュール帳</h1>
<table border="1">
<tr>
<th>日付</th><th>時刻</th><th>予定名</th><th>備考</th><th>削除</th>
</tr>
{foreach from=$sches item="sche"}
<tr>
<td>{$sche.s_date}</td>
<td>{$sche.s_time}</td>
<td>{$sche.title}</td>
<td>{$sche.memo}</td>
<td>
<input type="button" value="削除"
onclick="location.href='schedule_delete.php?sid={$sche.sid}'" /></td>
</tr>
{/foreach}
</table>
</body>
</html>