I’m reading Zend Framework manual and cannot understand how bootstrapping works particularly in ZF and in general.
They write:
Your Bootstrap class defines what resources and components to
initialize.
Ok. It means that the Bootstrap class should be instantiated the first of all.
But then then they write about the configuration ini file. And there are directives about the Bootstrap class itself in it:
1. bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
2. bootstrap.class = "Bootstrap"
So as I understand it means that it is not the Bootstarp class that is instantiated the first of all. The first of all something has to read the configuration file, get the info about the Bootstrap class and having that info to instantiate. Otherwise there is no need to have info about the Bootstrap class in configuration file. Because I can just do this:
require_once(/application/bootstrap.php)
$b = new Bootstrap();
and Bootstrap is instantiated.
But they say nothing about the one that reads the config file and then makes an instance of the Bootstrap.
- How the Bootstrap really works?
- Who instantiates it and on which stage?
- They say that the
APPLICATION_PATHis a constant. A constant has to be defined somewhere before it can be used. Where may it be defined if it is used in Bootstrap class?
Thank you.
If you look at the
index.phpfile that ships with ZF, this should answer most of those questions.The
APPLICATION_PATHconstant is defined inindex.php, and that is also where theZend_Applicationobject is created which simply bootstraps the application, and then runs it.There are 2 ways to tell your
Zend_Applicationwhere your bootstrap is located in ZF1.First way (explicitly set):
In the above example, the bootstrap class and the bootstrap script are passed as part of the
$optionsdirectly toZend_Application‘s constructor, along with theapplication.inifile.If you put the bootstrap class and script in your
application.inifile, then you can initializeZend_Applicationlike so:Zend_Applicationwill process theapplication.inifile and gather the Bootstrap information from there.You can then call
$application->bootstrap()->run();to run the application.To directly answer your questions:
inifile, it is the first thing take takes place. This sets up all the required components for your ZF application (e.g. Front Controller, Zend_View, Layouts, DB connection etc).APPLICATION_PATHis defined immediately in index.php