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
The line from application.ini
resources.layout[] =
is equivalent to:
_initLayout() {}
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:
_initSomeResource() {
$this->bootstrap('otherResource');
// ..
return $someValue;
}
_initOtherResource() {
// ..
}
So the order of instantiating of the resources is:
otherResource
someResource
Now, you may also use:
$bootstrap->getParam('someResource'); // returns $someValue
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, implementing Zend_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 from application.ini
, i.e.:
resources.view.encoding = "utf-8" ; in application.ini
Zend/Application/Resource/View.php (path to the resource class)
Zend_Application_Resource_View::setEncoding('UTF-8'); // equivalent pseudocode
Hope it's more clear now.