Commit 18afeb0e authored by 君塚 悠's avatar 君塚 悠

プログラム作成(schedule.php,MySmarty.class.php,schedule.tpl:Smartyを用いたスケジュール帳

parent 5180c9a5
<?php
// MySmartyのクラスファイル
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");
}
// 終了時にDBと接続を切る
public function __destruct()
{
$this -> _db -> desconnect();
}
// DBのデータを取得する
public function get_db()
{
return $this -> _db;
}
}
\ No newline at end of file
<?php
// DBのsheduleテーブルの内容を配列にコピーし、
// Smartyのテンプレートにその配列を割り当て、出力する。
require_once("MySmarty.class.php");
$o_smarty = new MySmarty();
$db = $o_smarty = new MySmarty();
$stt = $db -> prepare("SELECT * FROM schedule ORDER BY s_date, s_time");
$rs = $db -> excute($stt);
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();
// Smartyのテンプレートに値を割り当てる
$o_smarty -> assign("sches", $data);
// テンプレートを出力する
$o_smarty -> display("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>{$che.s_date}</td>
<td>{$che.s_time}</td>
<td>{$che.title}</td>
<td>{$che.memo}</td>
<td>
<input type = "button" value = "削除" onclick="location.href = 'schedule_dalete.php?sid =<?php print($row['sid']); ?>'" /></td>
</tr>
{/foreach}
</table>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment