Start your MVC (1) to integrate your site entry (reproduced) with PHP

xiaoxiao2021-03-06  180

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)

forceType Application / X-httpd-php

Document 1: (Test.php)

parse (); $ aa-> go ();?>>

File 2: (GoodControlr.php)

File 3: (BadControlr.php)

Document 4: (Application.php)

_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 ();}} ?>

转载请注明原文地址:https://www.9cbs.com/read-128883.html

New Post(0)