Zend Framework Configuration Step By Step Tutorial - Part 2: For easy maintenance, we put configuration data into separated file. For example, config.php. Let's do it.
Create a file named "config.php" within application. Enter following code:
<?
return array(
'webhost'=>'localhost',
'appName'=>'My First Zend',
'database'=>array(
'host'=>'localhost',
'dbname'=>'zend',
'username'=>'root',
'password'=>'admin'
)
);
?>
To call this file, we can use like this:
$config = new Zend_Config(require '../application/config.php');
This is complete code:
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
date_default_timezone_set('Europe/London');
$rootDir = dirname(dirname(__FILE__));
set_include_path($rootDir . '/library' . PATH_SEPARATOR . get_include_path());
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Registry.php';
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
require_once 'Zend/Config.php';
$config = new Zend_Config(require '../application/config.php');
$title = $config->appName;
$params = $config->database->toArray();
Zend_Registry::set('title',$title);
$arrName = array('Ilmia Fatin','Aqila Farzana', 'Imanda Fahrizal');
Zend_Registry::set('credits',$arrName);
$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
$DB->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Registry::set('DB',$DB);
Zend_Controller_Front::run('../application/controllers');
?>