其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
PHP MVC结构演示

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

  1. index.php
  2. <?php
  3. //控制器部分
  4.   $test = new class_test;
  5.   $test->set_username('hello,world!');
  6.   $tpl = new class_tpl('tpl.htm');
  7.   $tpl->setvar('title', 'phpmvc');
  8.   $tpl->setvar('msg', 'test');
  9.   $tpl->parse();
  10. //视图部分
  11. class class_tpl
  12. {
  13.   var $p_tpl;
  14.   function class_tpl($filename)
  15. {
  16.   $fh = fopen($filename, "r");
  17.   $this->p_tpl = fread($fh, filesize($filename));
  18.   fclose ($fh);
  19. }
  20. function setvar($t, $v)
  21. {
  22.   $this->p_tpl = str_replace('{'.$t.'}', $v, $this->p_tpl);
  23. }
  24. function parse()
  25. {
  26.   print $this->p_tpl;
  27. }
  28. }
  29. //模型部分
  30. class class_test
  31. {
  32.   var $model_test;
  33.   function class_test()
  34. {
  35.   $this->model_test = new model_test;
  36. }
  37. function set_username($value)
  38. {
  39.   $this->model_test->username = $value;
  40. }
  41. function get_username()
  42. {
  43.   return $this->model_test->username;
  44. }
  45. }
  46. //属性类 归属模型部分
  47. class model_test
  48. {
  49.   var $username = '';
  50. }
  51. ?>
  52. index.htm
  53. <!-- 显示 归属视图部分 -->
  54. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  55. "http://www.w3.org/TR/html4/loose.dtd">
  56. <html>
  57. <head>
  58. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  59. <title>{title}</title>
  60. </head>
  61. <body>
  62.   {msg} 
  63. </body>
  64. </html>



相关文章

相关软件