How to load config from a specific folder, for example: DOCROOT."assets/config/pre-load.php"
Defaults method will search in (APPPATH|MODPATH|SYSPATH)."/config/".DOCROOT."assets/config/pre-load"
,
but I need to go out from (APPPATH|MODPATH|SYSPATH)."/config/"
如何从特定文件夹加载配置,例如:DOCROOT。“assets / config / pre-load.php”默认方法将搜索(APPPATH | MODPATH | SYSPATH)。“/ config /”。DOCROOT。“assets / config / pre-load“,但我需要从(APPPATH | MODPATH | SYSPATH)出去。”/ config /“
1 个解决方案
#1
1
The default behaviour is to search in priority into 'APPPATH.'config/'
, and can be customized in your application/bootstrap.php
file. The default bootstrap file is well commented.
默认行为是将优先级搜索到'APPPATH.'config /',并且可以在application / bootstrap.php文件中进行自定义。默认的bootstrap文件评论很好。
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
You can add before (or after, depending of what you want) a new config file directory (relative to all Kohana::$_paths
you can also redefine, default being array(APPPATH, SYSPATH)
.
您可以在之前(或之后,根据您的需要)添加新的配置文件目录(相对于您也可以重新定义的所有Kohana :: $ _路径,默认为数组(APPPATH,SYSPATH)。
For example,
例如,
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
Kohana::$config->attach(new Config_File('../assets/config'));
if you want to add it later in the code (let's say in your controller initialisation) just add the line where you want. If the config file should be used only when all other config is missing, use FALSE for the 2nd parameter of the attach method (you can see comments inside php files of system/classes/Kohana/Config.php
or system/classes/Kohana/Config/File/Reader.php
).
如果你想稍后在代码中添加它(比如在你的控制器初始化中),只需在你想要的地方添加行。如果仅在缺少所有其他配置时才使用配置文件,请对attach方法的第二个参数使用FALSE(您可以在system / classes / Kohana / Config.php或system / classes / Kohana /的php文件中看到注释) Config / File / Reader.php)。
#1
1
The default behaviour is to search in priority into 'APPPATH.'config/'
, and can be customized in your application/bootstrap.php
file. The default bootstrap file is well commented.
默认行为是将优先级搜索到'APPPATH.'config /',并且可以在application / bootstrap.php文件中进行自定义。默认的bootstrap文件评论很好。
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
You can add before (or after, depending of what you want) a new config file directory (relative to all Kohana::$_paths
you can also redefine, default being array(APPPATH, SYSPATH)
.
您可以在之前(或之后,根据您的需要)添加新的配置文件目录(相对于您也可以重新定义的所有Kohana :: $ _路径,默认为数组(APPPATH,SYSPATH)。
For example,
例如,
/**
* Attach a file reader to config. Multiple readers are supported.
*/
Kohana::$config->attach(new Config_File);
Kohana::$config->attach(new Config_File('../assets/config'));
if you want to add it later in the code (let's say in your controller initialisation) just add the line where you want. If the config file should be used only when all other config is missing, use FALSE for the 2nd parameter of the attach method (you can see comments inside php files of system/classes/Kohana/Config.php
or system/classes/Kohana/Config/File/Reader.php
).
如果你想稍后在代码中添加它(比如在你的控制器初始化中),只需在你想要的地方添加行。如果仅在缺少所有其他配置时才使用配置文件,请对attach方法的第二个参数使用FALSE(您可以在system / classes / Kohana / Config.php或system / classes / Kohana /的php文件中看到注释) Config / File / Reader.php)。