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
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.