Correction status:qualified
Teacher's comments:完成的不错
<?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>
点击 "运行实例" 按钮查看在线实例