MVC with PHP (2)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.