Friday, April 15, 2011

How to configure Zend Framework

In Zend Framework you have four ways to use configuration file.
  • Zend_Config_Ini
  • Zend_Config_Json
  • Zend_Config_Xml
  • Zend_Config_Yaml
In most of the case everyone will use Zend_Config_In,

Using Zend_Config_Ini you can store configuration information's in the well known INI format and also you can get them in the application by using nested object property syntax. In this INI format we have some hierarchy of configuration data keys and also its possible to inherit between sections. You can use dot or period character (".") to follow hierarchy. A section may extend or inherit from another section by following the section name with a colon character (":") and the name of the section from which data are to be inherited.

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.db.adapter         = pdo_mysql
resources.db.params.host     = localhost 
resources.db.params.username = user_name
resources.db.params.password = user_password
resources.db.params.dbname   = database_name

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1 
In the above example, The DB was configured using a hierarchy of keys "resources.db.adapter" also the "Staging" was inherited( [staging : production] ) from "Production". Like this we can define configurations for different environment of our project.

No comments:

Post a Comment