- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
index.php:
<?php
define("TEMPLATE_FOLDER", "./templates/");
class Template
{
public function view($template, $data)
{
foreach($data as $key => $variable)
$$key = $variable;
require(TEMPLATE_FOLDER . $template . '.php');
foreach($data as $key => $variable)
unset($$key);
}
}
$template = new Template();
$data['test'] = array(1, 2, 3);
$template->view('index', $data);
?>
templates/index.php:
<html>
<body>
<?php foreach($test as $row): ?>
<?php echo $row ?><br/><br/>
<?php endforeach; ?>
</body>
</html>