Bootstrap, 也叫作引导程序. 它是Yaf提供的一个全局配置的入口, 在Bootstrap中, 你能够作不少全局自定义的工做.php
在一个Yaf_Application被实例化以后, 运行(Yaf_Application::run
)以前, 可选的咱们能够运行Yaf_Application::bootstrap
html
调用Bootstrapbootstrap
<?php $app = new Yaf_Application("conf.ini"); $app ->bootstrap() //可选的调用 ->run(); }
当bootstrap被调用的时刻, Yaf_Application就会默认的在APPLICATION_PATH下, 寻找Bootstrap.php, 而这个文件中, 必须定义一个Bootstrap类, 而这个类也必须继承自Yaf_Bootstrap_Abstract.app
实例化成功以后, 全部在Bootstrap类中定义的, 以_init开头的方法, 都会被依次调用, 而这些方法均可以接受一个Yaf_Dispatcher
实例做为参数.spa
一个Bootstrap的例子:code
Bootstrap.phphtm
<?php /** * 全部在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用, * 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher * 调用的次序, 和申明的次序相同 */ 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"); } }