欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

thinkPHP5.0框架獨立配置與動態(tài)配置方法

 更新時間:2017年03月17日 10:08:57   作者:chinalorin  
這篇文章主要介紹了thinkPHP5.0框架獨立配置與動態(tài)配置方法,結合實例形式分析了thinkPHP5.0框架獨立配置與靜態(tài)配置的功能、實現(xiàn)技巧與相關注意事項,需要的朋友可以參考下

本文實例講述了thinkPHP5.0框架獨立配置與動態(tài)配置方法。分享給大家供大家參考,具體如下:

獨立配置文件:

新版支持配置文件分離,只需要配置extra_config_list參數(shù)(在應用公共配置文件中)。

例如,不使用獨立配置文件的話,數(shù)據(jù)庫配置信息應該是在config.php中配置如下:

/* 數(shù)據(jù)庫設置 */
'database'       => [
  // 數(shù)據(jù)庫類型
  'type'    => 'mysql',
  // 服務器地址
  'hostname'  => '127.0.0.1',
  // 數(shù)據(jù)庫名
  'database'  => 'thinkphp',
  // 數(shù)據(jù)庫用戶名
  'username'  => 'root',
  // 數(shù)據(jù)庫密碼
  'password'  => '',
  // 數(shù)據(jù)庫連接端口
  'hostport'  => '',
  // 數(shù)據(jù)庫連接參數(shù)
  'params'   => [],
  // 數(shù)據(jù)庫編碼默認采用utf8
  'charset'   => 'utf8',
  // 數(shù)據(jù)庫表前綴
  'prefix'   => '',
  // 數(shù)據(jù)庫調(diào)試模式
  'debug'    => false,
],

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

'extra_config_list'   => ['database'],

定義之后,數(shù)據(jù)庫配置就可以獨立使用database.php文件,配置內(nèi)容如下:

/* 數(shù)據(jù)庫設置 */
return [
  // 數(shù)據(jù)庫類型
  'type'    => 'mysql',
  // 服務器地址
  'hostname'  => '127.0.0.1',
  // 數(shù)據(jù)庫名
  'database'  => 'thinkphp',
  // 數(shù)據(jù)庫用戶名
  'username'  => 'root',
  // 數(shù)據(jù)庫密碼
  'password'  => '',
  // 數(shù)據(jù)庫連接端口
  'hostport'  => '',
  // 數(shù)據(jù)庫連接參數(shù)
  'params'   => [],
  // 數(shù)據(jù)庫編碼默認采用utf8
  'charset'   => 'utf8',
  // 數(shù)據(jù)庫表前綴
  'prefix'   => '',
  // 數(shù)據(jù)庫調(diào)試模式
  'debug'    => false,
],

如果配置了extra_config_list參數(shù),并同時在config.php和database.php文件中都配置的話,則database.php文件的配置會覆蓋config.php中的設置。

獨立配置文件的參數(shù)獲取都是二維配置方式,例如,要獲取database獨立配置文件的type參數(shù),應該是:

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

要獲取完整的獨立配置文件的參數(shù),則使用:

Config::get('database');

系統(tǒng)默認設置了2個獨立配置文件,包括database和validate,分別用于設置數(shù)據(jù)庫配置和驗證規(guī)則定義。

動態(tài)配置:

設置配置參數(shù)

使用set方法動態(tài)設置參數(shù),例如:

Config::set('配置參數(shù)','配置值');
// 或者使用助手函數(shù)
config('配置參數(shù)','配置值');

也可以批量設置,例如:

Config::set([
  '配置參數(shù)1'=>'配置值',
  '配置參數(shù)2'=>'配置值'
]);
// 或者使用助手函數(shù)
config([
  '配置參數(shù)1'=>'配置值',
  '配置參數(shù)2'=>'配置值'
]);

更多關于thinkPHP相關內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎教程》及《PHP模板技術總結》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。

相關文章

最新評論