Blogger Information
Blog 37
fans 0
comment 1
visits 29825
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
下载安装composer,并把源设置为中国区镜像或阿里云镜像。 根据课堂案例,练习一下mvc的实现原理-2019-10-31
H先生
Original
831 people have browsed it

1.png


1.png



实例

<?php

// 路由解析
$server = $_SERVER;

//$path_info = $_SERVER['PATH_INFO'];		  // /home/index
$script_name = $_SERVER['SCRIPT_NAME'];   // /idnex.php
$request_uri = $_SERVER['REQUEST_URI'];	  // /index.php/home/index


$path_info = str_replace($script_name, '', $request_uri);

$path = ltrim($path_info,'/');

// 解析controller 和method
$controller_method = explode('/', $path);

$controller_method[0] = ucfirst($controller_method[0]);

$controller = $controller_method[0];
$method = $controller_method[1];

require_once __DIR__.'/controller/'.$controller_method[0].'.php';

$obj = new $controller();
$res = $obj->$method();

exit($res);

运行实例 »

点击 "运行实例" 按钮查看在线实例



实例

<?php



/**
 * 
 */
class Home{

	public function index(){
		echo 'hello MVC';
	}

	public function welcome(){
		require_once __DIR__.'/../view/welcome.php';
	}
}

运行实例 »

点击 "运行实例" 按钮查看在线实例


实例

<!DOCTYPE html>
<html>
<head>
	<title>welcome</title>
</head>
<body>
	<div style="font-size: 18px;text-align: center;color: red;">welcom to jiangsu</div>
	<?php echo date('Y-m-d H:i:s') ?>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

1.png

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