MVC原理
index.php
实例
<?php $server=$_SERVER; $path_info=$_SERVER['PATH_INFO']; // /home/index $path=ltrim($path_info,'/'); $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); ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例
Home.php 类文件
实例
<?php class Home { public function index(){ echo 'hello MVC'; } public function welcome(){ require_once __DIR__.'/../view/welcome.php'; } }
运行实例 »
点击 "运行实例" 按钮查看在线实例
welcome.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>welcome</title> </head> <body> <div style="font-size: 18px; text-align: center; color:red;"> WELCOME TO CHONGQIN <?php echo '<br>'; echo date('Y-m-d H:i:s'); ?> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例