index.php
<?php
//控制器部分
$test = new class_test;
$test->set_username('hello,world!');
$tpl = new class_tpl('tpl.htm');
$tpl->setvar('title', 'phpmvc');
$tpl->setvar('msg', 'test');
$tpl->parse();
//视图部分
class class_tpl
{
var $p_tpl;
function class_tpl($filename)
{
$fh = fopen($filename, "r");
$this->p_tpl = fread($fh, filesize($filename));
fclose ($fh);
}
function setvar($t, $v)
{
$this->p_tpl = str_replace('{'.$t.'}', $v, $this->p_tpl);
}
function parse()
{
print $this->p_tpl;
}
}
//模型部分
class class_test
{
var $model_test;
function class_test()
{
$this->model_test = new model_test;
}
function set_username($value)
{
$this->model_test->username = $value;
}
function get_username()
{
return $this->model_test->username;
}
}
//属性类 归属模型部分
class model_test
{
var $username = '';
}
?>
index.htm
<!-- 显示 归属视图部分 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>{title}</title>
</head>
<body>
{msg}
</body>
</html>