CodeIgniter 是一套給 PHP 網站開發者使用的應用程序開發框架和工具包。 它的目標是讓你可以更快速的開發,它提供了平常任務中所需的大量類庫, 以及簡單的接口和邏輯結構。經過減小代碼量,CodeIgniter 讓你更加專一 於你的創造性工做。php
http://codeigniter.org.cn/user_guide/general/welcome.htmlhtml
下圖說明了整個系統的數據流程:前端
index.php做爲web請求的入口文件,先分析學習一些index.php文件。web
一、肯定當前環境,生產?研發?測試? 而後針對錯誤信息級別進行設置。
二、設置CI的核心代碼文件夾的名稱,默認值是system。瀏覽器
/* *--------------------------------------------------------------- * SYSTEM DIRECTORY NAME *--------------------------------------------------------------- * * This variable must contain the name of your "system" directory. * Set the path if it is not in the same directory as this file. */ $system_path = 'system';
例如:把system文件夾名稱更改成cisys,這裏則須要把$system_path = 'cisys';,建議是把system修改如下名稱,以保證系統目錄的文件夾的獨特性!緩存
三、設置webapp的文件夾的名稱,默認值application安全
/* *--------------------------------------------------------------- * APPLICATION DIRECTORY NAME *--------------------------------------------------------------- * * If you want this front controller to use a different "application" * directory than the default one you can set its name here. The directory * can also be renamed or relocated anywhere on your server. If you do, * use an absolute (full) server path. * For more info please see the user guide: * * https://codeigniter.com/user_guide/general/managing_apps.html * * NO TRAILING SLASH! */ $application_folder = 'application';
例如,兩個application共用一套CI框架也是可行的,在實際項目當中,把一個application當成C端平臺,把另外一個application當成B端平臺,這樣這兩個application徹底能夠共用一套CI框架。這裏如何設置呢?第一個appcaliton爲http://www.xxx.com/,第二個application爲http://www.xxx.com/admin併發
$url = $_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:$_SERVER['QUERY_STRING']; if(strpos($url,'admin')!==false){ $application_folder = 'admin'; } else{ $application_folder = 'application'; }
四、設置view視圖文件夾的名稱,默認值爲空,則表明view文件夾在application/view下,如有值則表示此文件夾與index.php\system\application平級。app
五、獲取\驗證system的路徑的正確性。框架
六、獲取\驗證application的路徑的正確性。
七、獲取\驗證view的路徑的正確性。
八、加載CI的系統文件的入口文件
/* * -------------------------------------------------------------------- * LOAD THE BOOTSTRAP FILE * -------------------------------------------------------------------- * * And away we go... */ require_once BASEPATH.'core/CodeIgniter.php';
CodeIgniter.php做爲整個CI框架的入口文件,下一節重點分析分析。