thinkphp5.0獨立配置

來源:互聯網
上載者:User

標籤:

獨立設定檔

新版支援設定檔分離,只需要配置extra_config_list參數(在應用公用設定檔中)。

例如,不使用獨立設定檔的話,資料庫配置資訊應該是在config.php中配置如下:

/* 資料庫設定 */‘database‘              => [    // 資料庫類型    ‘type‘        => ‘mysql‘, // 伺服器位址 ‘hostname‘ => ‘127.0.0.1‘, // 資料庫名 ‘database‘ => ‘thinkphp‘, // 資料庫使用者名稱 ‘username‘ => ‘root‘, // 資料庫密碼 ‘password‘ => ‘‘, // 資料庫連接連接埠 ‘hostport‘ => ‘‘, // 資料庫連接參數 ‘params‘ => [], // 資料庫編碼預設採用utf8 ‘charset‘ => ‘utf8‘, // 資料庫表首碼 ‘prefix‘ => ‘‘, // 資料庫偵錯模式 ‘debug‘ => false,],

如果需要使用獨立設定檔的話,則首先在config.php中添加配置:

‘extra_config_list‘     => [‘database‘],

定義之後,資料庫配置就可以獨立使用database.php檔案,配置內容如下:

/* 資料庫設定 */return [    // 資料庫類型    ‘type‘        => ‘mysql‘, // 伺服器位址 ‘hostname‘ => ‘127.0.0.1‘, // 資料庫名 ‘database‘ => ‘thinkphp‘, // 資料庫使用者名稱 ‘username‘ => ‘root‘, // 資料庫密碼 ‘password‘ => ‘‘, // 資料庫連接連接埠 ‘hostport‘ => ‘‘, // 資料庫連接參數 ‘params‘ => [], // 資料庫編碼預設採用utf8 ‘charset‘ => ‘utf8‘, // 資料庫表首碼 ‘prefix‘ => ‘‘, // 資料庫偵錯模式 ‘debug‘ => false,],

如果配置了extra_config_list參數,並同時在config.php和database.php檔案中都配置的話,則database.php檔案的配置會覆蓋config.php中的設定。

獨立設定檔的參數擷取都是二維配置方式,例如,要擷取database獨立設定檔的type參數,應該是:

Config::get(‘database.type‘);

要擷取完整的獨立設定檔的參數,則使用:

Config::get(‘database‘);

系統預設設定了2個獨立設定檔,包括database和validate,分別用於設定資料庫配置和驗證規則定義。

thinkphp5.0獨立配置

聯繫我們

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