Php MVC single point Portal Php MVC single point portal? /Index. php & lt ;? /*** MVC demo ** only implements the most basic MVC functions, excluding security processing, data filtering, and other optimization measures. */Define ('site _ path' mvc spof entry of Php
MVC single point of entry for Php
?
/Index. php
/**
* MVC demo
* Only implement the most basic MVC functions, excluding security processing, data filtering, and other optimization measures.
*/
Define ('site _ path', str_replace (", '/', dirname (_ FILE _); // define the system directory
$ Controller = (! Empty ($ _ GET ['controller'])? $ _ GET ['controller']: 'index'; // gets the controller. the default index
$ Action = (! Empty ($ _ GET ['action'])? $ _ GET ['action']: 'index'; // method name, default index
$ Controller_name = $ controller. 'controller ';
$ Controller_file = SITE_PATH. '/app/controller/'. $ controller_name. '. class. php'; // Obtain the controller file
If (file_exists ($ controller_file )){
Require_once ($ controller_file );
$ Controller = new $ controller_name ();
$ Controller-> {$ action. 'action '}();
} Else {
Die ('The corresponding controller cannot be found! ');
}
?>
?
Corresponding demo
/App/controller/testController. class. php (note the path)
/**
* MVC demo
* Only implement the most basic MVC functions, excluding security processing, data filtering, and other optimization measures.
*/
Class testController
{
Function testAction (){
Echo 'Hello, World! ';
}
}
?>
Open the browser and enter http: // path/to/yoursite/index. php? Controller = test & action = test (change your path accordingly). If you see Hello, World! The first step of MVC is that the single point of access is successful!