Chinaunix
标题:
PHP MVC结构演示
[打印本页]
作者:
leaslie
时间:
2006-03-07 01:42
标题:
PHP MVC结构演示
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
}
本文来自ChinaUnix博客,如果查看原文请点:
http://blog.chinaunix.net/u/12334/showart_81963.html
作者:
wengbin22
时间:
2009-06-29 17:25
为什么没人顶呢??
作者:
江岚
时间:
2009-07-13 16:33
提示:
作者被禁止或删除 内容自动屏蔽
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2