PHP MVC结构演示
时间:2006-03-07 来源:leaslie
index.php
PHP代码:
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 = '';
}
?>
tpl.htm
PHP代码:
{title}
{msg}
PHP代码:
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 = '';
}
?>
tpl.htm
PHP代码:
{title}
{msg}
相关阅读 更多 +