Cakephp 執行主要流程_PHP教程

來源:互聯網
上載者:User
載入基本檔案
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)做一些處理
返回或輸出視圖資料。
流程完畢。

http://www.bkjia.com/PHPjc/321450.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321450.htmlTechArticle載入基本檔案 cake/basics.php 裡面定義了常用的方法以及時間常量 $TIME_START = getMicrotime(); 記錄開始執行時間 cake/config/paths.php 裡面定義一些基本...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.