This example describes the Zend_config_ini usage of the Zend Framework tutorial. Share to everyone for your reference, specific as follows:
Zend_config_ini allows developers to store and read configuration data in an application in a familiar INI format through nested object property syntax. The INI format has expertise in providing the inheritance capability between the hierarchical structure that has the configuration Data key and the Configuration data section. Configure data hierarchy by using dots or periods (.) Separates the key values. A section can be extended or inherited from another section by using the name of a section with a colon (:) and inherited configuration data after the section's name.
Parse_ini_file
Zend_config_ini uses the parse_ini_file () PHP function. Review this document to learn about its specific behavior, which is used in Zend_config_ini, such as true, false, yes, no, and null, and how these special values operate.
Key separator
By default, the key separator character is a period (.). However, this can be modified by modifying the $options key ' Nestseparator ' when constructing the Zend_config_ini object. For example:
$options [' nestseparator '] = ': ';
$config = new Zend_config_ini ('/path/to/config.ini ',
' staging ',
$options);
Example: Using Zend_config_ini
This example illustrates the basic use of Zend_config_ini to load configuration data from the INI file.
In this example, there are configuration data for production systems (production system) and development systems (staging system).
Because the development system configuration data is similar to the configuration data of the production system, the development system section inherits from the Production system section.
In this case, the result (decision) is arbitrary and it can be reversed, that is, the production system section inherits from the development system section, although this is not possible for more complex scenarios.
Next, assume that the following configuration data is included in the/path/to/config.ini:
Production Site configuration data
[Production]
webhost = www.example.com
database.adapter = pdo_mysql
database.params.host = db.example.com
database.params.username = dbuser
Database.params.password = Secret
Database.params.dbname = dbname
Development site configuration data is configured for data integration from the production site and can be overridden if needed
[Staging:production]
Database.params.host = dev.example.com
database.params.username = Devuser
Database.params.password = Devsecret
Next, assume that the developer needs to take development configuration data from the INI file. This is very simple, as long as you specify the INI file and the development system section to load the data:
$config = new Zend_config_ini ('/path/to/config.ini ', ' staging ');
echo $config->database->params->host; Output "dev.example.com"
echo $config->database->params->dbname;//Output "dbname"
Attention
Table Zend_config_ini Constructor Parameters:
parameter |
comment |
$filename |
to load INI file. |
|
[section] in the INI file will be loaded. Set this parameter to NULL, and all the sections will be loaded. In addition, an array of section names is provided to load multiple sections. |
$options = False | An array of
options. The following keys are supported:
|
More interested in Zend related content readers can view the site topics: "The introduction of the Zend Framework frame", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Course", "PHP object-oriented Programming Program , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the Zend Framework.