Kohana Framework: way to load config using absolute file path

663 views Asked by At

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/"

1

There are 1 answers

0
Asenar On BEST ANSWER

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.

/**
 * 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).

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 ).