We know that thinkphp has public function files and configuration files, in the common directory, the default common/function.php is a public function file, conf/config.php is a public profile. OK, so how do you customize other public functions and configuration files? Here we have to talk about two configuration parameters Load_ext_file and Load_ext_config.
1. Load_ext_file configuration is a custom function file, such as I want to create a common.php file in the common directory, then the config.php can be configured load_ext_file=> ' common ', This will automatically load the common.php file.
Common/conf/config.phpreturn Array (load_ext_file=> ' Common ');
Then write a method in the common.php, such as:
function T_dump ($data) {if (!empty ($data)) {echo ' <pre> '; Var_dump ($data); Echo ' </pre> '; }}
Call T_dump (Array ()) in the controller, output:
Array (3) {[0]=> int (1) [1]=> int (2) [2]=> int (3)} If another file is created under Common, test.php, define a test function in the test.php file Functio N () {echo ' Test ';} Then the direct call in the controller will be an error: Calls to undefined function home\controller\test () If you add test in config.php, ' load_ext_file ' = ' common, Test ', it executes normally. 2.load_ext_config is used for custom profiles, such as config.php you want to introduce an additional configuration file global.php so you can configure it in config.php:
Load_ext_config=> ' Global ' then you create a global.php file in the Conf directory, write a configuration parameter return array (' mongo_dbname ' = ' idacker ');
Then C calls Echo C (' Mongo_dbname ')
Output: Idacker3. Load principle, in fact, the loading of custom functions and configuration files is attributed to the Load_ext_file function,/** * load dynamic extension files * @var string $path file Paths * @return void */function load_ext_file ($path) { // Load Custom External file if ($files = c (' Load_ext_file ')) { $files = explode (', ', $ files); foreach ($files as $file) { $file = $path. ' common/'. $file. PHP '; if (Is_file ($file)) include $file; } } Load Custom dynamic profile if ($configs = c (' Load_ext_config ')) { &Nbsp; if (is_string ($configs)) $configs = explode (', ', $configs); foreach ($configs as $key + $config) { $file = is_file ($config)? $ config : $path. ' conf/'. $config. Conf_ext; if (Is_file ($file)) { is_numeric ($ Key)? C (Load_config ($file)): C ($key, Load_config ($file)); } } }} The function needs to pass in a $path directory path. For example, if we pass in Common_path, the common.php function and global.php configuration file created in the above two steps will be loaded.
thinkphp loading custom external files and configuration files