溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CI框架入口文件index.php文件分析​

發(fā)布時間:2020-10-01 19:12:51 來源:網(wǎng)絡(luò) 閱讀:2306 作者:Jeff_Linux 欄目:web開發(fā)



CI框架入口文件index.php文件分析

CI框架入口文件index.php文件分析​



<?php
/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 *
 */
//設(shè)置環(huán)境配置,development,testing,production三種。其本質(zhì)就是設(shè)置error_reporting()的級別
    define('ENVIRONMENT', 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */
//根據(jù)選擇的環(huán)境,設(shè)置error_reporting()的級別
if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;
                                                          
        case 'testing':
        case 'production':
            error_reporting(0);
        break;
        default:
            exit('The application environment is not set correctly.');
    }
}
/*
 *---------------------------------------------------------------
 * SYSTEM FOLDER NAME
 *---------------------------------------------------------------
 *
 * This variable must contain the name of your "system" folder.
 * Include the path if the folder is not in the same  directory
 * as this file.
 *
 */
//設(shè)置系統(tǒng)的路徑,必須包含system這個目錄,這是CI的核心所在目錄
    $system_path = 'system';
/*
 *---------------------------------------------------------------
 * APPLICATION FOLDER NAME
 *---------------------------------------------------------------
 *
 * If you want this front controller to use a different "application"
 * folder then the default one you can set its name here. The folder
 * can also be renamed or relocated anywhere on your server.  If
 * you do, use a full server path. For more info please see the user guide:
 * http://codeigniter.com/user_guide/general/managing_apps.html
 *
 * NO TRAILING SLASH!
 *
 */
//設(shè)置個人應(yīng)用的目錄
    $application_folder = 'application';
/*
 * --------------------------------------------------------------------
 * DEFAULT CONTROLLER
 * --------------------------------------------------------------------
 *
 * Normally you will set your default controller in the routes.php file.
 * You can, however, force a custom routing by hard-coding a
 * specific controller class/function here.  For most applications, you
 * WILL NOT set your routing here, but it's an option for those
 * special instances where you might want to override the standard
 * routing in a specific front controller that shares a common CI installation.
 *
 * IMPORTANT:  If you set the routing here, NO OTHER controller will be
 * callable. In essence, this preference limits your application to ONE
 * specific controller.  Leave the function name blank if you need
 * to call functions dynamically via the URI.
 *
 * Un-comment the $routing array below to use this feature
 *
 */
//用于設(shè)置額外的控制器目錄,當你的控制器沒有放在application/controllers的時候需要通過以下配置來指定你的controllers目錄的位置
//總共有三種方式,第一種指定控制器的目錄,第二種指定控制的類名,第三種指定控制器中函數(shù)名稱
    // The directory name, relative to the "controllers" folder.  Leave blank
    // if your controller is not in a sub-folder within the "controllers" folder
    // $routing['directory'] = '';
    // The controller class file name.  Example:  Mycontroller
    // $routing['controller'] = '';
    // The controller function you wish to be called.
    // $routing['function'] = '';
//下面是用來定制一些配置參數(shù)
//允許你設(shè)置一些參數(shù),或者覆蓋任何在config.php文件的中的默認配置值
/*
 * -------------------------------------------------------------------
 *  CUSTOM CONFIG VALUES
 * -------------------------------------------------------------------
 *
 * The $assign_to_config array below will be passed dynamically to the
 * config class when initialized. This allows you to set custom config
 * items or override any default config values found in the config.php file.
 * This can be handy as it permits you to share one application between
 * multiple front controller files, with each file containing different
 * config values.
 *
 * Un-comment the $assign_to_config array below to use this feature
 *
 */
    // $assign_to_config['name_of_config_item'] = 'value of config item';
//下面是不要編輯的地方
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS.  DO NOT EDIT BELOW THIS LINE
// --------------------------------------------------------------------
/*
 * ---------------------------------------------------------------
 *  Resolve the system path for increased reliability
 * ---------------------------------------------------------------
 */
    // Set the current directory correctly for CLI requests
    // 對于當前的請求,將請求轉(zhuǎn)至定義的目錄
    if (defined('STDIN'))
    {
        //dirname(__FILE__) 返回當前文件的目錄,并通過chdir切換過去。
        chdir(dirname(__FILE__));
    }
//realpath 返回指定文件的絕對路徑
//
    if (realpath($system_path) !== FALSE)
    {
        //設(shè)置成絕對路徑,并在最后添加/ 補全路徑
        $system_path = realpath($system_path).'/';
    }
//確保有一個斜線
    // ensure there's a trailing slash
    $system_path = rtrim($system_path, '/').'/';
//判斷這個路徑是否存在
    // Is the system path correct?
    if ( ! is_dir($system_path))
    {
        exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
        //path 獲取文件路徑信息
        //    PATHINFO_DIRNAME - 只返回 dirname
        //    PATHINFO_BASENAME - 只返回 basename
        //    PATHINFO_EXTENSION - 只返回 extension
    }
//現(xiàn)在我們知道了路徑的相關(guān)信息了,就可以來定義一些信息了
/*
 * -------------------------------------------------------------------
 *  Now that we know the path, set the main path constants
 * -------------------------------------------------------------------
 */
    // The name of THIS file
    define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
    // The PHP file extension
    // this global constant is deprecated.
    define('EXT', '.php');
    // Path to the system folder
    //將\\替換成 /
    define('BASEPATH', str_replace("\\", "/", $system_path));
    // Path to the front controller (this file)
                                                          
    define('FCPATH', str_replace(SELF, '', __FILE__));
    // Name of the "system folder"
    define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
    // The path to the "application" folder
    //定義APP的目錄,從中可以發(fā)現(xiàn)APP目錄有兩個一個是和system同一級目錄,還有一個就是在system的子目錄中
    if (is_dir($application_folder))
    {
        define('APPPATH', $application_folder.'/');
    }
    else
    {
        if ( ! is_dir(BASEPATH.$application_folder.'/'))
        {
            exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
        }
        define('APPPATH', BASEPATH.$application_folder.'/');
    }
/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *
 * And away we go...
 *
 */
//加載啟動文件
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
/* Location: ./index.php */


向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI