MVC with PHP(二)_PHP教程

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

MVC with PHP(一)中的bug的问题是存在,最大的问题是日志系统的问题,等完成这这个介绍后我后把全部更正的程序源码打包
出来,这里就暂时不做更改了.
先来看看在application.class.php中是如何建立controller实例的:
PHP代码:--------------------------------------------------------------------------------
/**
* 执行函数
*
* 此类唯一对外的一个接口
**/
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);
}
--------------------------------------------------------------------------------
Application这个类在实例后唯一可进行调用的一个函数,它根据用户的URL请求来分析得出所需要的Controller类名,然后实例化这个类(上面标1的地方),再调用从URL中获取的动作名称(上面标2的地方),
这个举一个简单的例子:
URL: http://localhost/?module=news&action=showList
Application通过分析这个URL重到controllerClassName=news, action=showList,然后它将在包含处理这个controller类的文件名(在Application->getControllerFile()中进行),然后实例化News这个
controller类(标1的地方), 随后调用它的动作showList(标2的地方).
来看看newsController.php中的内容:
=============================================================
PHP代码:--------------------------------------------------------------------------------
/**
* FileName: newsController.php
* Introduce: 新闻控制类
*
* @author: 大师兄
* @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.com true http://www.bkjia.com/PHPjc/631836.html TechArticle MVC with PHP(一)中的bug的问题是存在,最大的问题是日志系统的问题,等完成这这个介绍后我后把全部更正的程序源码打包 出来,这里就暂时不...
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!