phpeveryday.com

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


Zend Framework Config: Creating File Configuration

Tag: framework, zend, zend framework, configuration, file   Category: PHP Database
post: 21 Apr 2008 read: 721


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

?>


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