thinkPHP5.0 Framework independent configuration and dynamic configuration method

Source: Internet
Author: User
This article mainly introduced the thinkPHP5.0 framework independent configuration and dynamic configuration method, combined with the example form analysis of the thinkPHP5.0 framework independent configuration and static configuration functions, implementation skills and related considerations, the need for friends can refer to the following

This paper describes the thinkPHP5.0 framework independent configuration and dynamic configuration method. Share to everyone for your reference, as follows:

Standalone configuration file:

The new version supports profile separation and requires only configuration extra_config_list parameters (in the application public profile).

For example, if you do not use a standalone configuration file, the database configuration information should be configured in config.php as follows:


/* Database Settings */' database '       = + [  //DB type ' type  '    = ' mysql ',  //server address  ' hostname '  = ' 127.0.0.1 ',  //database name ' databases  '  = ' thinkphp ',  //database user name  ' username '  = ' root ',  //Database password  ' password ' + '  ,  //Database connection Port  ' hostport ' = ', '/  /Database connection Parameters  ' Params ' =   = [],  //Database encoding defaults  to UTF8 ' charset ' = ' utf8 '   ,  //database table prefix  ' prefix '   = > ',  //Database debug mode  ' Debug '    = False,],


If you need to use a standalone configuration file, first add the configuration in config.php:


' extra_config_list '   = [' Database '],


After the definition, the database configuration can use the database.php file independently, the configuration content is as follows:


/* Database Settings */return [  //Database type ' type  '    = ' mysql ',  //server address  ' hostname '  = ' 127.0.0.1 ',  //Database name  ' databases '  = ' thinkphp ',  //Database username  ' username ' +  ' root ',  //Database Password  ' password ' = ' + '  ,  //Database connection Port  ' hostport ' + '  ,  //database connection parameter  ' params '   = = [],  //Database encoding defaults to UTF8  ' charset '   = ' utf8 ',  //database table prefix  ' prefix '   = ',  Database debug mode  ' Debug '    = False,],


If the Extra_config_list parameter is configured and both are configured in both the config.php and database.php files, the configuration of the database.php file overrides the settings in config.php.

The parameter acquisition for a standalone profile is a two-dimensional configuration, for example, to get the type parameter of the database standalone configuration file, it should be:


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


To obtain the parameters for a complete stand-alone profile, use:


Config::get (' database ');


The system defaults to 2 separate configuration files, including database and validate, which are used to set the configuration and validation rule definitions.

Dynamic configuration:

Setting Configuration parameters

Use the Set method to set parameters dynamically, for example:


Config::set (' config parameter ', ' config value ');//or Use Assistant function config (' config parameter ', ' config value ');


can also be set in batches, for example:


Config::set ([  ' config parameter 1 ' = ' = ' configuration value ',  ' configuration parameter 2 ' = ' + ' config value ') '//or use the Helper function config ([  ' config parameter 1 ' = ' config value ',  ' Configuration parameter 2 ' = = ' configuration value ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.