免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2374 | 回复: 2
打印 上一主题 下一主题

PHP MVC结构演示 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-07 01:42 |只看该作者 |正序浏览
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

论坛徽章:
0
3 [报告]
发表于 2009-07-13 16:33 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
2 [报告]
发表于 2009-06-29 17:25 |只看该作者
为什么没人顶呢??
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP