Get Your Zend Config Parameters from Outside of the bootstrapped Zend Framework Application.

Get Your Zend Config Parameters from Outside of the bootstrapped Zend Framework Application. 

The majority of my time is spent writing code using the Zend Framework. Sometimes I’m asked to write a separate script that is periodically scheduled to run – in most cases this consists of a report generation script scheduled to run in the early hours of the morning. However, all of the configuration data that is necessary – for example to connect to the database – is sitting in the configs directory in the application.ini file.  The code example below demonstrates how to get your config data object from outside of your bootstrapped Zend Framework application:

require_once ‘Zend/Loader.php’ Zend_Loader::loadClass(‘Zend_Config_Ini’);

$config = new Zend_Config_Ini(‘/home/server/application/configs/application.ini’,'live’); $db = $config->db->params;

The first stage is to load the Zend_Config.Ini class using the Zend Loader. The second stage is to instantiate the Zend_Config_Ini object passing in 2 parameters. The first parameter is the directory of your config file. The second parameter is the environmental variable, very useful if you have multiple environments such as staging, development, live, etc. In this example the database connection parameters are saved in the $db variable to be used later to connect to a database.

This entry was posted in Managed Hosting. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>