程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> PHP綜合 >> Cakephp 執行主要流程

Cakephp 執行主要流程

編輯:PHP綜合
加載基本文件
cake/basics.php 裡面定義了常用的方法以及時間常量
$TIME_START = getMicrotime(); 記錄開始執行時間
cake/config/paths.php 裡面定義一些基本路徑
cake/lib/object.php cake的基本類
cake/lib/inflector.php 這裡主要是處理單復數,帶下劃開命名以及駝峰式命名
cake/lib/configure.php 裡面提供文件配置的讀寫,路徑的設置,以及加載文件的方法
cake/lib/cache.php 緩存的操作

Configure::getInstance(); 開始對項目的配置
config/core.php 項目的配置文件
config/bootstrap.php 項目的入口文件

App::import(‘Core', array(‘Dispatcher')); 加載核心,開始做正事了,GO
$Dispatcher = new Dispatcher();
$Dispatcher->dispatch($url); 開始執行,通過對當前的url解析,如果你設置了壓縮Js、Css,則對這些文件壓縮輸出,如果你對頁面設置緩存,則直接輸出緩存頁面,最後查找相應的Controller。如果找不到,則進行相應的錯誤處理。
實例化當前Controller,確定視圖路徑,實例化Component,獲得僅當前Controller[不包含父類Controller]的方法
對當前Controller中私有方法、帶admin路由或者帶prefix的方法進行保護,不允許直接訪問
設置當前Controller的基本屬性,如base、here、webroot、plugin、params、action、 passedArgs[array_merge($this->params['pass'],$this->params['named'])]
調用Controller中的constructClasses方法
執行__mergeVars方法,該方法對父子類的components、helpers、uses等屬性進行特殊合並處理
調用Component->init()方法,載入用戶設置的系列components(Session為默認),並默認enabled屬性為true。(該屬性可以後期在beforeFilter裡修改)
調用Component->initialize()方法,若系列components裡有這個initialize方法並且該component 的enabled為true,則調用該components->initialize方法(這裡enabled用戶好像無法通過 Controller設置,只能為true)
調用當前Controller中beforeFilter()方法,這個方法是個好東西^_^
調用Component->startup()方法,同樣,若系列components裡有這個startup方法並且該component的 enabled為true,則調用該components->startup方法(這裡enabled倒是可以通過beforeFilter設 置),該方法也是components裡最重要的方法,比如Auth就在這裡大作文章^_^
開始執行當前Controller裡的Action方法
如果設置autoRender為true,則根據調用當前Controller的render()方法,否則返回或輸出Action方法的返回的數據
調用Controller的render()方法時,先調用當前Controller中的beforeRender()方法
加載視圖渲染類
調用Component->beforeRender()方法,同樣,若系列components裡有這個beforeRender方法並且該 component的enabled為true,則調用該components->beforeRender方法(這裡enabled可以通過 beforeFilter設置)
獲取當前Model的數據驗證錯誤信息,給View使用
調用View的render()方法
載入相關Helper助手
調用Helper的beforeRender()方法
調用Helper的afterRender()方法
相關的緩存處理
執行renderLayout()方法,當然前提你要允許渲染布局,默認為default.ctp布局文件
調用Helper的beforeLayout()方法
調用Helper的afterLayout()方法
調用Component->shutdown()方法,同樣,若系列components裡有這個shutdown方法並且該component的 enabled為true,則調用該components->shutdown方法(這裡enabled可以通過beforeFilter設置)
執行當前Controller裡的afterFilter方法,這裡你可以對視圖的輸出內容($controller->output)做一些處理
返回或輸出視圖數據。
流程完畢。
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved