General Configuration
todo, description of benefits of static properties for configuration
Core Configuration
The first configuration task of any new Kohana installation is changing the Kohana::init settings in application/bootstrap.php. These settings are:
booleanerrors- Use internal error and exception handling? (Default
TRUE) Set toFALSEto disable the Kohana error and exception handlers. booleanprofile- Do internal benchmarking? (Default
TRUE) Set toFALSEto disable internal profiling. Disable in production for best performance. booleancaching- Cache the location of files between requests? (Default
FALSE) Set toTRUEto cache the absolute path of files. This dramatically speeds up Kohana::find_file and can sometimes have a dramatic impact on performance. Only enable in a production environment, or for testing. stringcharset- Character set used for all input and output. (Default
"utf-8") Should be a character set that is supported by both htmlspecialchars and iconv. stringbase_url- Base URL for the application. (Default
"/") Can be a complete or partial URL. For example "http://example.com/kohana/" or just "/kohana/" would both work. stringindex_file- The PHP file that starts the application. (Default
"index.php") Set toFALSEwhen you remove the index file from with URL rewriting. stringcache_dir- Cache file directory. (Default
"application/cache") Must point to a writable directory.
Cookie Settings
There are several static properties in the Cookie class that should be set, particularly on production websites.
stringsalt- Unique salt string that is used to used to enable signed cookies
integerexpiration- Default expiration lifetime in seconds
stringpath- URL path to restrict cookies to be accessed
stringdomain- URL domain to restrict cookies to be accessed
booleansecure- Only allow cookies to be accessed over HTTPS
booleanhttponly- Only allow cookies to be accessed over HTTP (also disables Javascript access)
Configuration Files
Configuration is done in plain PHP files, which look similar to:
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'setting' => 'value',
'options' => array(
'foo' => 'bar',
),
);
If the above configuration file was called myconf.php, you could acess it using:
$config = Kohana::config('myconf');
$options = $config['options'];
Kohana::config also provides a shortcut for accessing individual keys from configuration arrays using "dot paths".
Get the "options" array:
$options = Kohana::config('myconf.options');
Get the "foo" key from the "options" array:
$foo = Kohana::config('myconf.options.foo');
Configuration arrays can also be accessed as objects, if you prefer that method:
$options = Kohana::config('myconf')->options;