Accessing Bootstrap Resources from Anywhere

Alek­sey V. Zap­parov posts a very nice solu­tion to a very com­mon ques­tion when deal­ing with Boot­strap resources;

Hello,
You can either reg­is­ter pre­cious resources in reg­istry, e.g.:


protected function _initMyResource()
{
$res = 'foobar';
Zend_Registry::set('myResource', $res);
return $res;
}

Or you can reg­is­ter the whole boot­strap, so you can place in it’s con­struc­tor, some­thing like this:


public function __construct($application) {
parent::contstruct($application);
Zend_Registry::set('Bootstrap', $this);
}

So later you’ll be able to access resources via:

$res = Zend_Registry::get('myResource');

or:

$res = Zend_Registry::get('Bootstrap')->getResource('MyResource');

And there is another way to get your boot­strap­per from almost
every­where:

$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$resource = $bootstrap->getResource('MyResource');

Sin­cerely yours,
Alek­sey V. Zap­parov A.K.A. ixti

Tags: , ,

Leave a Comment

*

Get Adobe Flash playerPlugin by wpburn.com wordpress themes