©
本文档使用
php.cn手册 发布
(Yaf >=1.0.0)
Yaf_Application::bootstrap — 调用bootstrap
$bootstrap
] )指示Yaf_Application去寻找Bootstrap,并按照声明的顺序,执行所有在Bootstrap类中定义的以_init开头的方法。 如果没有提供变量bootstrap,Yaf默认会去application.directory中寻找Bootstrap。
bootstrap
A Yaf_Bootstrap_Abstract instance
Yaf_Application instance
Example #1 A Bootstrap() example
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
function _initConfig ( Yaf_Dispatcher $dispatcher ) {
echo "1st called\n" ;
}
function _initPlugin ( $dispatcher ) {
echo "2nd called\n" ;
}
}
?>
Example #2 Yaf_Application::bootstrap() example
<?php
defined ( 'APPLICATION_PATH' ) // APPLICATION_PATH will be used in the ini config file
|| define ( 'APPLICATION_PATH' , __DIR__ )); //__DIR__ was introduced after PHP 5.3
$application = new Yaf_Application ( APPLICATION_PATH . '/conf/application.ini' );
$application -> bootstrap ();
?>
以上例程的输出类似于:
1st called 2nd called
[#1] brandon at brandonlamb dot com [2011-12-29 20:50:25]
Here is an example of a Bootstrap loading a session class then loading a database class and using a db configuration from the application config.
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initSession(Yaf_Dispatcher $dispatcher)
{
$session = new Vendor\Session();
$session->start();
}
public function _initDatabase(Yaf_Dispatcher $dispatcher)
{
$config = Yaf_Application::app()->getConfig()->application->database;
Yaf_Registry::set('db', Vendor\Database($config));
}
}
?>