How to pass variables to Bootstrap.php
Is there a way how I could pass variables to Bootstrap.php? This is how I bootstrap in the index.php:
// let's go!
$application = new Zend_Application(APPLICATION_ENVIRONMENT,
APPLICATION_PATH.'/configs/application.ini');
try {
$application->bootstrap();
$application->run();
} catch (Exception $exception) {
echo $exception->getMessage();
exit(1);
}
In one method of my Bootstrap.php class I need to have access to some variables from index.php and using $GLOBALS is just awful:
protected function _initFilePathConverter()
{
require_once (PATH_TO_L开发者_开发百科IB_UTIL.'/FilePathConverter.php');
$this->aFilePathConverter = new FilePathConverter();
$this->aFilePathConverter->AddPathPairs($GLOBALS['REAL_PATHS'], $GLOBALS['HTTP_PATHS']);
}
You can use Zend_Registry.
E.g. in the index.php you could say:
Zend_Registry::set('Real_Paths', array('my', 'paths'));
Make sure you do that after you've created the Zend_Application object, so the Zend autoloader has been initialized. And then in the bootstrap:
$real_paths = Zend_Registry::get('Real_Paths');
Try this:
index.php
<?
$testvar = 'testing';
?>
bootstrap.php
protected function _initFilePathConverter()
{
global $testvar;
echo $testvar;
}
精彩评论