ThinkPHP V5.1.18 cross-module invocation scope problem

1, there are a module and b module respectively, each of which has its own config configuration file

2. I call the function in the b module controller in module a, but this function uses the config configuration of module a

3. How can I make it use the configuration file in b module

Mar.25,2021

this is the mechanism of tp5, which automatically loads the configuration file under the current module by default. You can dynamically load the function of the b template before calling the function of the b module.

Config::load(APP_PATH.'b/config.php');

Let me take a look at the source code of tp5.1. The load class of config is as follows.

/**
 * 
 * @access public
 * @param  string    $file 
 * @param  string    $name 
 * @return mixed
 */
public function load($file, $name = '')
{
    if (is_file($file)) {
        $name = strtolower($name);
        $type = pathinfo($file, PATHINFO_EXTENSION);
        if ('php' == $type) {
            return $this->set(include $file, $name);
        } elseif ('yaml' == $type && function_exists('yaml_parse_file')) {
            return $this->set(yaml_parse_file($file), $name);
        }
        return $this->parse($file, $type, $name);
    }
    return $this->config;
}
The parameters of

file can be as follows:

$obj->load('../application/b/config.php');

it's not too much trouble. I suggest defining a constant APP_PATH

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb4bf4-24fb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb4bf4-24fb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?