The bug in MVC with PHP (1) exists, and the biggest problem is the log system problem. After completing this introduction, I will package the source code of all the corrected programs.
This will not be changed for the moment.
Let's take a look at how to create a controller instance in application. class. php:
PHP code :--------------------------------------------------------------------------------
/**
* Execute a function
*
* This type of unique external interface
**/
Public function run ()
{
$ This-> parsePath ();
$ This-> checkSecurity ($ this-> module, $ this-> action );
1. $ controller = new $ this-> controllerClassName ();
2. $ controller-> {$ this-> action }();
$ This-> writeLog ($ this-> module, $ this-> action );
}
--------------------------------------------------------------------------------
The Application class is the only function that can be called after the instance. It analyzes the required Controller class name based on the user's URL request, then instantiate this class (the place marked with 1 above) and call the action name obtained from the URL (the place marked with 2 above ),
Here is a simple example:
URL: http: // localhost /? Module = news & action = showList
The Application analyzes the URL to repeat controllerClassName = news, action = showList, and then it will include the file name that processes the controller class (in Application-> getControllerFile ), then instantiate the News
Controller class (place marked with 1), and then call its action showList (place marked with 2 ).
Let's take a look at the content in newsController. php:
========================================================== ==================================
PHP code :--------------------------------------------------------------------------------
<? Php
/**
* FileName: newsController. php
* Introduce: News Control
*
* @ Author: Master
* @ Email: teacherli@163.com
* @ Version $ Id $
* @ Copyright 2004-10-26
**/
Include_once ("./controller/comm/controller. class. php ");
Include_once ("./model/news/newsModel. php ");
Class NewsController extends Controller