状态 草稿
Todo elaborate on load(), include_paths()
官方最后更新时间 2008/08/11 11:23

配置类(Config Class)

提示:

在 Kohana v2.2 已不推荐使用此类。现在其方法均放在了 Kohana 类 类中

由于其方法均放在了 Kohana 类 类中,以下就不再进行翻译。

在哪设置配置?

配置文件必须放在 config 文件夹下面,这个文件可以放在 system,application 或者模块 module 目录下面。Application 高于 system 目录(即目录下的配置参数可以覆盖 system 目录下同样配置参数)。Modules 高于 system 但低于 application文件。

配置文件的格式必须是下面的形式:

$config = array
(
	'language' => 'en_US',
	'timezone' => ''
);

方法

检索配置项

Config::item($key, $slash = FALSE, $required = TRUE) 可以检索配置项并返回一个字符串,数组或布尔型。 $slash will force a forward slash at the end of the item. $required determines whether an item is required or not.

Config::item('locale.language'); //returns the language from the **locale.php** file and returns the config['language'] item.

设置配置项

For setting configuration items in realtime you must enable this setting in the config.php file. (core.allow_config_set)

Config::set($key, $value) sets a configuration item, returns TRUE on success or FALSE when it didn't succeed.

Config::set('locale.language','nl_NL');

Note:

If you want to set a configuration in realtime make sure the config.allow_config_set is set to TRUE in application/config.php

获得 include 路径

Config::include_paths($process= FALSE) gets the include paths and returns an array. First in the array is the application path, last will be the system path, other items will be include paths set in the configuration item 'core.include_paths'. $process, if true, will reprocess the include_paths.

Config::include_paths();

加载配置文件

Config::load($name, $required = TRUE) loads a configuration file. Config::item() loads them as well if they're not already loaded and retrieves the items straightaway.

Config::load('locale');
core/config.txt · 最后更改: 2008/09/03 02:31 由 icyleaf