I'm beginning with Zend Framework and I would like to understand Bootstrap file. I've learned all _init
methods are executed by default but it seems confusing to me. Anyway that is not what I would like to ask.
A came around the $this->bootstrap('layout');
action and I'm not sure if I understand this. Is this the resource.layout variable in application.ini file? I would like to really understand the bootstrap process in deep.
I'm asking you for step by step explanation.
Thanks in advance!
So this is my bootstrap file:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH
));
return $moduleLoader;
}
function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$view->doctype('XHTML1_STRICT');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
$view->headTitle()->setSeparator(' - ');
$view->headTitle('Zend Framework Tutorial');
}
}
Best Answer
The line from
application.ini
is equivalent to:
in
Bootstrap.php
Both of them are initializing new object, and this object is set as a
bootstrap
param, which is a container for some application resources (values returned by_init
methods).There are executed one by one, so to ensure one resource is initialized before the the current one, you force the order, using:
So the order of instantiating of the resources is:
otherResource
someResource
Now, you may also use:
Note, that you may encounter
Circular Dependency
error, when you try to execute each other before each one.You may use as many
_init
methods you need, but to make them reusable, you may separate them to their own class, implementingZend_Application_Resource_Abstract
class.There are some out of the box application resources, which you may find in
Zend/Application/Resource
directory. These are the resources, you are refering fromapplication.ini
, i.e.:Hope it's more clear now.