phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Zend Framework Config: Using INI File Configuration

Tag: framework, zend, zend framework, configuration, file   Category: PHP Framework
post: 21 Apr 2008 read: 1,086


Zend Framework Configuration Step By Step Tutorial - Part 3: We have learn about how to use zend_config at previous post. Now, we try to implement using ini file.

Create a file named "config.ini" within application. Enter following sample config:


; Production site configuration data
[app]
webhost           = www.example.com
title			  = My Zend Framework
database.host     = localhost
database.username = root
database.password = admin
database.dbname     =  zend

To read that config, we use like this:


require_once 'Zend/Config/Ini.php';

$config = new Zend_Config_Ini('../application/config.ini','app');

$title  = $config->appName;
$params = $config->database->toArray();

Following 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/Ini.php';

$config = new Zend_Config_Ini('../application/config.ini','app');

$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');

?>


Series this article:
Zend Framework Config: Using Array Configuration
Zend Framework Config: Creating File Configuration
Zend Framework Config: Using INI File Configuration
Zend Framework Config: Using XML File Configuration

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting