kohana引导

Bootstrap

bootstrap的位置在application/bootstrap.php。它负责建立Kohana的环境和执行的主响应。它是被index.php包含进去的。

建立环境

bootstrap首先设置时区和语言环境,然后增加Kohana的autoloader使级联文件系统工作。你可以在这里添加你的应用程序需要的所有设置。

// Sample excerpt from bootstrap.php with comments trimmed down

// Set the default time zone.
date_default_timezone_set(‘America/Chicago’);

// Set the default locale.
setlocale(LC_ALL, ‘en_US.utf-8’);

// Enable the Kohana auto-loader.
spl_autoload_register(array(‘Kohana’, ‘auto_load’));

// Enable the Kohana auto-loader for unserialization.
ini_set(‘unserialize_callback_func’, ‘spl_autoload_call’);

Initialization and Configuration(初始化和配置)

kohana调用Kohana::init来初始化,并启用日志和配置读写器。

// Sample excerpt from bootstrap.php with comments trimmed down

Kohana::init(array(‘
base_url’ => ‘/kohana/’,
index_file => false,
));

// Attach the file writer to logging. Multiple writers are supported.
Kohana::$log->attach(new Kohana_Log_File(APPPATH.’logs’));

// Attach a file reader to config. Multiple readers are supported.
Kohana::$config->attach(new Kohana_Config_File);

您可以添加条件语句,使引导具有基于某些设置不同的值。例如,我们发现无论是现场检查$_ SERVER[‘HTTP_HOST’],并设置缓存,分析,等等。因此。这仅仅是一个例子,也有许多不同的方式来完成同样的事情。
// Excerpt from http://github.com/isaiahdw/kohanaphp.com/blob/f2afe8e28b/application/bootstrap.php
… [trimmed]

/**
* Set the environment status by the domain.
*/
if (strpos($_SERVER[‘HTTP_HOST’], ‘kohanaframework.org’) !== FALSE)
{
// We are live!
Kohana::$environment = Kohana::PRODUCTION;

// Turn off notices and strict errors
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
}

/**
* Initialize Kohana, setting the default options.
… [trimmed]
*/
Kohana::init(array(
‘base_url’ => Kohana::$environment === Kohana::PRODUCTION ? ‘/’ : ‘/kohanaframework.org/’,
‘caching’ => Kohana::$environment === Kohana::PRODUCTION,
‘profile’ => Kohana::$environment !== Kohana::PRODUCTION,
‘index_file’ => FALSE,
));

… [trimmed]

Modules(模块)

模块使用Kohana::modules()加载进来的。包含模块是可选的。阵列中的每个键应该是模块的名称,并且该值是所述路径模块,相对或绝对的。

// Example excerpt from bootstrap.php

Kohana::modules(array(
‘database’ => MODPATH.’database’,
‘orm’ => MODPATH.’orm’,
‘userguide’ => MODPATH.’userguide’,
));

Routes(路由)

路由是由Route::set() 定义的

// The default route that comes with Kohana 3
Route::set(‘default’, ‘(<controller>(/<action>(/<id>)))’)
->defaults(array(
‘controller’ => ‘Welcome’,
‘action’ => ‘index’,
));

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注