Home > Backend Development > PHP Tutorial > MVC with PHP (2)_PHP tutorial

MVC with PHP (2)_PHP tutorial

WBOY
Release: 2016-07-13 11:00:07
Original
1076 people have browsed it

There are bugs in MVC with PHP (1). The biggest problem is the log system. After completing this introduction, I will package all the corrected program source codes
and I will not make any changes here for the time being. .
Let’s first take a look at how to create a controller instance in application.class.php:
PHP code:---------------------- -------------------------------------------------- --------
/**
* Execution function
*
* The only external interface of this type
**/
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 based on the user's URL request. name, then instantiate this class (marked 1 above), and then call the action name obtained from the URL (marked 2 above),
Here is a simple example:
URL: http:/ /localhost/?module=news&action=showList
Application returns to controllerClassName=news, action=showList by parsing this URL, and then it will process the file name of this controller class (in Application->getControllerFile() ), then instantiate the News
controller class (marked 1), and then call its action showList (marked 2).
Let’s take a look at the content in newsController.php:
== ================================================== =========
PHP code:---------------------------------- ------------------------------------------------
< ?php
/**
* FileName: newsController.php
* Introduce: News Control Class
*
* @author: Senior Brother
* @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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631836.htmlTechArticle There are bugs in MVC with PHP (1). The biggest problem is the log system, etc. After completing this introduction, I will package all the corrected program source codes, which will not be included here for the time being...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template