//index.php
<?php
$server=$_SERVER;
// echo "<pre>";
// print_r($server);
//request_uri /index.php/home/view
//script_name /index.php
//path_info /home/view////
$request_uri =$_SERVER['REQUEST_URI'];
//request_uri /index.php/home/view
$script_name =$_SERVER['SCRIPT_NAME'];//script_name /index.php
$path_info =str_replace($script_name,"", $request_uri);//但这里改了这后,还是无法去掉index.php
// echo $path_info;
// $path_info= $_SERVER['PATH_INFO'];
$path_info= ltrim($path_info,'/');
$path_info= explode("/", $path_info);
$cclass=ucfirst($path_info[0]); $method= $path_info[1];
require_once __DIR__."./controller/".$cclass.".php";
$obj = new $cclass() ;$obj->$method();
//controller/ home.php
<?php
/*** */
// require_once "../modle/db.php";
class Home{
function index() {
echo "How can I use MVC";
}
function method() {
echo "How can I use MVC";
// require_once __DIR__."/../view/".$cclass.".php";
$a="变量往下一个页面传;";//变量往下一个页面传;
require_once __DIR__."/../view/".__CLASS__.".php";
}
}
//view/home.php
<?php
echo $a;//接收到的变量
echo "<br/>this is view page!,收到变量";