Blogger Information
Blog 18
fans 0
comment 0
visits 14956
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel 学习
牛粪也香的博客
Original
639 people have browsed it

//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!,收到变量";

image.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