封装MVC(五)

        完成封装(四)后,新建model.class.php,代码如下:

<?php

    class Model extends SQLQuery{

        protected $_model;

        function __construct() {

            $this->connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);

            $this->_model = get_class($this);

            $this->_table = strtolower($this->_model)."s";

        }

        function __destruct() {

        }

    }

         如图所示:

               


          

           新建视图基类为template.class.php,具体代码如下:

 

<?php

    class Template {

       protected $variables = array();

       protected $_controller;

       protected $_action;

       function __construct($controller,$action) {

           $this->_controller = $controller;

           $this->_action =$action;

       }

       /* 设置变量 */ 

       function set($name,$array)
       {
            if(!empty($name)){

               $this->_action = $name;
            }
            $this->variables = $array;
       }

       /* 显示模板 */

       function render() {

           if(!empty($this->variables)){
                foreach ($this->variables as $key => $value) {

                    extract(array($key=>$value));    //将变量导入当前符号表
                }
           }

           if (file_exists(ROOT.DS. 'application' .DS. 'views' .DS. $this->_controller .DS. 'header.php')) {

               include(ROOT.DS. 'application' .DS. 'views' .DS. $this->_controller .DS. 'header.php');

           } else {

               include(ROOT.DS. 'application' .DS. 'views' .DS. 'header.php');

           }

           include (ROOT.DS. 'application' .DS. 'views' .DS. $this->_controller .DS. $this->_action . '.php');

           if (file_exists(ROOT.DS. 'application' .DS. 'views' .DS. $this->_controller .DS. 'footer.php')) {

               include (ROOT.DS. 'application' .DS. 'views' .DS. $this->_controller .DS. 'footer.php');

           } else {

               include (ROOT.DS. 'application' .DS. 'views' .DS. 'footer.php');

           }

        }

    }


       如图所示:

             






       做完了以上这么多操作,基本上整个MVC框架已经出来了,下面就该制作我们的站点了。我们要做的站点其实很简单,一个ToDo程序。

       下面操作请点击:封装MVC(六)




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值