I don't think that using .ini or .xml file is a good idea with high traffic projects because every page load causes parsing config.ini or .xml file.
Is there any way to replace using .ini/.xml with regular php array as config? Now php ini looks like that...
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "Europe/London"
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.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = rob
resources.db.params.password = 123456
resources.db.params.dbname = zf-tutorial
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view.doctype = "XHTML1_STRICT"
[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
I want something like this...
<?php
$config = array(
'production' => array(
['phpSettings.display_startup_errors'] => 0,
['phpSettings.display_errors'] => 0,
),
);
Is it possible? What should I do and how should I tell application to use my own Config.php?
Thank you and sorry for my English.
UPD: I think that passing array to Zend_Application constructor is a right way?
Yes, you can use an array to initialize the data for a Zend_Config
object ; take a look at this page of the Zend Framework manual (quoting what's arround Example #1) :
Normally it is expected that users would use one of the adapter classes such as
Zend_Config_Ini
orZend_Config_Xml
, but if configuration data are available in a PHP array, one may simply pass the data to theZend_Config
constructor in order to utilize a simple object-oriented interface
You should also take a look at Example #2 on the same page (quoting what's arround it) :
It is often desirable to use a pure PHP-based configuration file. The following code illustrates how easily this can be accomplished
Basically, you first create a PHP file that contains the configuration :
// config.php
return array(
...
...
);
And, then, from another file, use than configuration file :
$config = new Zend_Config(require 'config.php');
But note that doing that, you'll lose the ability to easily modify the configuration, writing it back to the .ini
file -- which, depending on your situation, might eventually (or not) be a problem.
A solution that could be used is to cache the Zend_Config
data :
.ini
file.ini
file.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With