Bootstrap file is used to run the Zend framework. It execute with every request. To work with bootstrap we require htaccess file, which help to execute bootstrap file first with any page requested by the user.
Following is the code of .htacess for framework.
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
In above expression it mention that any request except js|ico|txt|gif|jpg|png|css files, will run the index.php which also be a bootstrap file.
In bootstrap file, we need to specify the requirement and configuration. In beginning we set the default include path. so, when we will call any require file then it will search the file in the set path folder.
So, see how we going to use it.
define('ROOT_DIR',dirname(__FILE__));
set_include_path(get_include_path(). PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');
In above code, I defined the ROOT_DIR Constant which is full path for current directory and I used set_include_path() function to set the default include and require path for file we will need in future
during program execution.
I used it for following files:
1. Library Files - which will be inside ROOT_DIR . '/library/' directory.
2. Model Files - which will be inside ROOT_DIR . '/application/models/' directory.
3. Form Files - which will be inside ROOT_DIR . '/application/forms/' directory.
4. Previous Default Folder - get_include_path().
So, next time if i need any files inside above folder then i don't need to specify the full path, only i need to specify the file name.
Now, we need to define the controller path. So, we need Front.php file, which is inside library/Zend/Controller folder.
$front= Zend_Controller_Front::getInstance();
$front->setControllerDirectory( './application/controllers');
$front->dispatch();
Font.php contain getInstance static function which is used to create class object by reference. Inside this class there is function
called setControllerDirectory() used to define the controller folder. Atlast dispath() function which is work like a kick start.
Whole code is following index.php
define('ROOT_DIR',dirname(__FILE__));
set_include_path(get_include_path(). PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');
$front= Zend_Controller_Front::getInstance();
$front->setControllerDirectory( './application/controllers');
$front->dispatch();
It is the minimum code to create a bootstrap file. we can also create advance bootstrap to work with advance work.
Following is the code of .htacess for framework.
RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
In above expression it mention that any request except js|ico|txt|gif|jpg|png|css files, will run the index.php which also be a bootstrap file.
In bootstrap file, we need to specify the requirement and configuration. In beginning we set the default include path. so, when we will call any require file then it will search the file in the set path folder.
So, see how we going to use it.
define('ROOT_DIR',dirname(__FILE__));
set_include_path(get_include_path(). PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');
In above code, I defined the ROOT_DIR Constant which is full path for current directory and I used set_include_path() function to set the default include and require path for file we will need in future
during program execution.
I used it for following files:
1. Library Files - which will be inside ROOT_DIR . '/library/' directory.
2. Model Files - which will be inside ROOT_DIR . '/application/models/' directory.
3. Form Files - which will be inside ROOT_DIR . '/application/forms/' directory.
4. Previous Default Folder - get_include_path().
So, next time if i need any files inside above folder then i don't need to specify the full path, only i need to specify the file name.
Now, we need to define the controller path. So, we need Front.php file, which is inside library/Zend/Controller folder.
$front= Zend_Controller_Front::getInstance();
$front->setControllerDirectory( './application/controllers');
$front->dispatch();
Font.php contain getInstance static function which is used to create class object by reference. Inside this class there is function
called setControllerDirectory() used to define the controller folder. Atlast dispath() function which is work like a kick start.
Whole code is following index.php
define('ROOT_DIR',dirname(__FILE__));
set_include_path(get_include_path(). PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');
$front= Zend_Controller_Front::getInstance();
$front->setControllerDirectory( './application/controllers');
$front->dispatch();
It is the minimum code to create a bootstrap file. we can also create advance bootstrap to work with advance work.