In the previous post about setting project environment setting http://ganeshhs.com/php/php-configuring-project-environment-using-ini-file , zend config plays a vital role in initializing the environment variables and by default, configuration data made available through Zend_Config are read-only.
Lets write the ini configuration file application/config.ini
[staging] db.adapter = PDO_MYSQL db.config.host = localhost db.config.username = mysql_user db.config.password = mysql_password db.config.dbname = mysql_database show_errors = true [production] db.adapter = PDO_MYSQL db.config.host = mysql_host_name db.config.username = mysql_user db.config.password = mysql_password show_errors = false
Lets add the following code in boot strap file public/index.php
<?php
require_once 'Zend/Config/Ini.php';
$config = new Zend_Config_Ini('/path/to/config.ini', 'staging');
// in our project we will be using path application/config.ini
// Try printing host name
echo "Host Name: ".$config->db->config->host;
?>
Reference Links:
http://ganeshhs.com/php/php-configuring-project-environment-using-ini-file
http://framework.zend.com/manual/en/zend.config.theory_of_operation.html
RSS feed for comments on this post · TrackBack URI
Leave a reply