首頁  >  文章  >  後端開發  >  cakephp Cakephp 執行主要流程

cakephp Cakephp 執行主要流程

WBOY
WBOY原創
2016-07-29 08:42:22926瀏覽

載入基本檔案
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)做一些處理
返回或輸出視圖資料。
流程完畢。

以上就介紹了cakephp Cakephp 執行主要流程,包含了cakephp的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn