MVC with PHP(二)
來源:互聯網
上載者:User
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代碼:--------------------------------------------------------------------------------
<?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