Zend Framework------Management configuration file

Source: Internet
Author: User
Tags zend zend framework

Turn from: http://ifeeline.com/archives/tag/zend-framework

Through the Zend_config class, the Zend Framework provides several ways to write configuration data:
Creates an array with a hierarchy in the boot file.
Create an already given INI file. When processing an INI file, the framework even allows you to extend the configuration section and override the key values.
Use an XML file.

Ways to use arrays:
To add a configuration array to the boot file, simply create an array with the key/value structure. You can also nest values to create structures that have multiple hierarchies. When the Zend_config class is initialized by an array, the key values of the array are converted to properties, providing a very clear interface.

1 $configArray = (
2 ' Domain ' => ' ifeeline.com ',
3 ' Database ' => array (' name ' => ' dbname ', ' Password ' => ' pasword ');
4 );
5 $config = new Zend_config ($configArray);
6 echo $config->database->name;

Ini method:
The main difference between the INI method and the array method is that the INI file can define the overridden data, which can be used in certain situations, such as when running on a test server or running on a production server. This provides a degree of flexibility, but also results in a lot of duplication, so the INI format of the Zend Framework also provides a configuration section -level extension.
INI configuration file:
[Production]
Domain = ifeeline.com
Database.name = dbname;
Database.password = password

[Staging:production]
Domain = beta.ifeeline.com
Database.name = Stagingdb

In order for the Zend_config class to know which setting to use, you need to instantiate the Zend_config_ini class by using the following code:

1 $config = new Zend_config_ini (' Config.ini ', ' staging ');
2 echo $config->database->password;

The first argument points to the INI file, and the second parameter represents the configuration section that is used.

XML methods:

The method of accessing XML configuration data is the same as the access method when configuring the system with the INI file.

1 $config = new Zend_config_xml (' Config.xml ', ' staging ');
2 echo $config->database->password;

The first parameter of the Zend_config_ini and Zend_config_xml class specifies the configuration file, which should normally be a specified path, such as: './application/config/config.ini ', or it can be arranged according to your own intent, The second parameter is the configuration information for which section is used, and the third parameter is whether to throw an exception.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.