zoukankan      html  css  js  c++  java
  • PHP MVC设想,MVC框架构思(一)

    其实我又在想,MVC是什么东西,为什么要采用MVC,它能干啥?

    分层的好处是什么?

    什么叫敏捷开发?

    如何有效的扩展,框架?

    Thinkphp for mvc ######################我有很多的疑问

    如果实现亿万数据查询?

    如何提高访问速度?

    SEO优化

    如果提高性能?################这些问题困扰着我?

    希望可以得到高手的指点,一起学习!

    我的QQ是:1598135958 

    好了,由于最近自己在做一个项目,用了thinkphp,天天看这玩意儿,我就在想,要不自己也写写看,或者效率,性能没有人家的高,试试看呢

    开始贴写代码出来?

    这是我的目录结构,和thinkphp的目录结构很像,基本是上一致的,如果他又一个类库,我这里暂时没有,不过我会在接下来的日子里,我要把它慢慢摸索出来

    首先我有一个入口文件index.php,代码如下

    <?php 
    $modules = $_GET['module']; //模块
    $action = $_GET['action']; //模块下的动作
    $module = $modules.'Action'; //模块文件名

    if (file_exists('Lib/Action/'.$module.'.class.php'))
    {
    include_once ('Lib/Action/'.$module.'.class.php'); //根据URL加载
    $module = new $module();
    $module->$action();
    }
    else
    {
    echo 'no is file!';
    }
    ?>

    访问地址是这样子的http://localhost/MVC/index.php?module=Index&action=index

    访问了之后,获取了到不同的参数,自动引入文件

    此时看到:

    include_once ('Lib/Action/'.$module.'.class.php');        //根据URL加载                
    $module= new $module();
    $module->$action();
    等同于什么呢?
    include_once ('Lib/Action/IndexAction.class.php');    //根据URL加载     
    $module = new IndexAction();//实例化
    $module->index();//当前模块下的这个方法
    那好了,接下来,再看看Lib/Action/IndexAction.class.php里面到底又什么东西呢?
    <?php     
    //我是模块叫IndexAction,它下面又一个方法index,这个模块让model(模型)干事去,它还让index.php去表现(显示),末后的model它都干了些啥?
    class IndexAction{
    function index(){
    include_once ("Lib/Model/IndexModel.class.php"); //一个模块对应着一个模型,当然这个模型你可以完全不要,直接在模块里面做这份工作,建议还是遵循MVC
    $model = new IndexModel();              //同样的我干了一件事情,我把$model请出来了
    $title = $model->title;                //我找$model要了一个title,我想把这个title给我亲爱的index.php
    include_once('Tpl/default/Index/index.php');   //用来显示的,这里我更不就没有用到html
    }
    }
    ?>

     让我model出来秀一下Lib/Model/IndexModel.class.php

    <?php 
    class IndexModel{
    public $title = "zongzi";
    }
    ?>

    再看看的的模板Tpl/default/Index/index.php

    <?php
    echo $title
    ?>

      

    //昨天看着看着就搞了这么一个玩意儿,接下来我会去深究,扩展一个分页的类,扩展一个模板类,当然还又很多工作要做,或者我根本就不用模板类,自己感觉这样处理速度不够快,直接PHP,再缓存,加生成静态,等等,

    希望更多的朋友可以加入进来,我们一起讨论下!,一起学习,我的电话是15558530459,qq:1598135958 我的email是mezongzi@gmail.com

  • 相关阅读:
    ZZNU 正约数之和 2094
    ZZNUOJ 2022 摩斯密码
    POJ
    NYOJ 1277Decimal integer conversion (第九届河南省省赛)
    hrbust 2080链表 【贪心】
    hdu-5707-Combine String
    POJ 2442-Sequence(优先队列)
    Reversion Count
    python 07篇 内置函数和匿名函数
    python 06篇 常用模块
  • 原文地址:https://www.cnblogs.com/wangzong/p/2129353.html
Copyright © 2011-2022 走看看