Blogger Information
Blog 34
fans 0
comment 0
visits 23020
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第19-21章 php原生实战-2019年10月15日20时00分
Tommy-黄天浩的博客
Original
542 people have browsed it

作业:用MVC搭建一个框架,自动加载视图

M:model模型,对数据库管理、操作;

V:view试图,前端视图格式化;

C:controller控制器,请求派发器,用户点击事件进行处理

目录结构如下图所示:

QQ截图20191108151203.png

indexAction.php代码如下所示:

<?php
//引入模型Model
include 'Model/function_index.php';

functio_index.php代码如下所示:

<?php

function auto_load_tpl($tplName){
//    自动加载视图
    include 'View/'.$tplName.'.php';
}

View/index.php代码如下所示:

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>MVC框架</title>
</head>
<body>
    <h1>MVC自动加载视图实例</h1>
</body>
</html>

入口文件index.php代码如下:

<?php

//获取GET方式传入的值,这里简化没有进行判断
$tplName=$_GET['a'];
//可以判断传入的值导入相应的Controller控制器

include 'Controller/'.$tplName.'Action.php';
//使用自动加载的方法
auto_load_tpl($tplName);


Correction status:qualified

Teacher's comments:不错, 流程明白了
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post