First, implement a unified website entry (the method of calling the Controler layer in the MVC, that is, the control layer)
Everyone may often see such a path on the Internet (http://www.aaa.com/aaa/bbb/aaaid=5), which makes people don't understand, such a website implementation has several possibilities:
1. The extension of the hidden file is the benefits of this practice, and there is no need for personal feelings.
2. Use the redirection rules of the website to realize the virtual path;
3. Improve the virtual path in the way for mandatory file parsing.
Use the second third method to realize the unified interface of the website, reasonable integrated website, better reflecting the security and architecture of the website, most of these two ways of websites use "MVC" mode structure
Construction and implementation.
Below is an example
The access path is as follows:
... / TEST / ******* / BAD ... / TEST / ******* / Good ("******" can be used Character string replace, "......." is your web path)
The directory structure of the file is as follows
| - .htaccess | - TEST | - Application.php | - Controler / GoodControl.php | - Controler / BadControl.php Note File ".htaccess", can not be created directly under Windows, can be on the command line Built in mode.
File 0 :(. Htaccess) (this file is used to change the Apache configuration method)
Document 1: (Test.php)
php / * ----------------------------------- * Test.php * * as you Site entrance file * Used to initialize and entry * call to perform Controler call * ---------------------------------------------------------------------------------------------- ----- * / Require "Application.php"; $ AA = New Application (); $ aa-> parse (); $ aa-> go ();?>>
File 2: (GoodControlr.php)
php / * ----------------------------------- * GoodControlr.php * * is used Control URL = / test / good access * ------------------------------------- * / Class GoodController {/ * * Control Class Call Method, Unique External Interface * / Function Control () {Echo "this is from goodControl URL = ********* / test / good"; }}?>
File 3: (BadControlr.php)
php / * ----------------------------------- * BadControlr.php * * is used Control URL = / Test / Bad access * ------------------------------------- * / Class BadControler {/ * * Control Class Call Method, Unique External Interface * / Function Control () {Echo "this is from goodControl URL = ********* / test / bad"; }}?>
Document 4: (Application.php)
php / * ---------------------------------- Application.php * * is used Implement the unified entry of the website, call the Controler class * --------------------------------- * / Class Application {// Used to record the action VAR $ action; // controle file path name VAR $ controlefile; // Controler class name var $ controllerclass; function application () {} function parse () {$ this- > _PARSEPATH (); $ this -> _ getControlerFile (); $ this -> _ getControlrClassName ();} / * * Resolution of the current access path, get action * / function _parsePath () {List ($ PATH, $ Param) = EXPLODE ("?", $ _SERVER ["Request_uri"]); $ POS = STRRPOS ($ PATH, "/"); $ this-> Action = Substr ($ PATH, $ POS 1);} / * * By action $ action, resolve the path of the Controler file to be used by this $ action * / function _getcontrolerFile () {$ this-> controlefile = "./controle/"..PHIS .AACTION."Control.php"; IF (! ") DIE (" Controler file name (") DIE (" Controler file name ("); resolution error"); Require_Once $ this-> controllerfile;} / * * By action $ action, Resolution gets the $ action to use CO NTROLER Classification * / Function _GetControlrClassName () {$ this-> ControlerClass = $ this-> action. "controller"; if (! Class_exists) Die ("Controler class name (") Die ("Controler class name (". $ this- > ControleRClass. ") Analysis Error");} / * * Call Controler, execute the control of Controler * / Function Go () {$ C = New $ this-> ControlerClass (); $ c-> control ();}} ?>