Bootstrap, 也叫做引導程序. 它是Yaf提供的一個全局配置的入口, 在Bootstrap中, 你可以做很多全局自定義的工作.
### 使用Bootstrap
在一個Yaf_Application被實例化之后, 運行(Yaf_Application::run)之前, 可選的我們可以運行Yaf_Application::bootstrap
#### 改寫index.php文件如下:
`<?php
define("APP_PATH", realpath(dirname(__FILE__)));
$app = new Yaf_Application(APP_PATH . "/conf/application.ini");
$app->bootstrap()->run();
`
當bootstrap被調用的時刻, Yaf_Application就會默認的在APPLICATION_PATH下, 尋找Bootstrap.php, 而這個文件中, 必須定義一個Bootstrap類, 而這個類也必須繼承自Yaf_Bootstrap_Abstract.
實例化成功之后, 所有在Bootstrap類中定義的, 以_init開頭的方法, 都會被依次調用, 而這些方法都可以接受一個Yaf_Dispatcher實例作為參數.
也可以通過在配置文件中修改application.bootstrap來變更Bootstrap類的位置.
### 簡單的示例Bootstrap.php
`<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initDefaultName(Yaf_Dispatcher $dispatcher) {
$dispatcher->setDefaultModule("Index")->setDefaultController("Index")->setDefaultAction("index");
}
}`