【PHP】 Smarty 隔離スレ 【テンプレート】
■ このスレッドは過去ログ倉庫に格納されています
0001nobodyさん
2008/02/02(土) 00:21:09ID:6cKcKeTp0271nobodyさん
2008/10/14(火) 02:40:48ID:???0272nobodyさん
2008/10/14(火) 03:44:58ID:???よろしくお願いしまーす
<? // きょうつう(init.php)
define('DS', DIRECTORY_SEPARATOR);
define('TEMPLATE_DIR', 'tpl');
function include_template($name, $vars) {
// てきとうにかんすうをていぎします
function h($str){ return htmlspecialchars($str); }
function strip($str){ return preg_replace('/[\n\r]/', '', $str); }
extract($vars);
include TEMPLATE_DIR . DS . $name;
}
?>
0273nobodyさん
2008/10/14(火) 03:46:43ID:???require_once 'init.php';
$rows = array(
array('time'=>time(), 'name'=>'foo', 'value'=>1),
array('name'=>'bar')
);
include_template('tpl.php', compact('rows'));
?>
<? // てんぷれーと(tpl.php) ?>
<? $title = 'ページタイトル'; ?>
<? include 'header.php' ?>
<table>
<? foreach((array) $rows as $row): ?>
<? ob_start('strip') ?>
<tr>
<td><?=h ($row['time'] ? strftime('%T', $row['time']) : '00:00:00') ?></td>
<td><?=h ($row['name']) ?></td>
<td><?=h ($row['value'] ? $row['value'] : 'DEFAULT') ?></td>
<tr>
<? ob_get_flush() ?>
<? endforeach ?>
</table>
<? include 'footer.php' ?>
でもsmartyのメソッドチェインてきなやつはよいとおもいます
■ このスレッドは過去ログ倉庫に格納されています