Chapter 3 of zendframework Learning (Core Component-use configuration data to read data from xml configuration files)

Source: Internet
Author: User
Tags webhost

ManyProgramUse an XML file as the storage carrier for configuration data. You can use zend_config_xml to easily read data from the xml configuration file. The format is as follows:
Zend_config_xml (filename, section, allowmodifications)

The first parameter is the XML file name, and the second parameter is the node name. Third, I don't need to explain it. The following is not so much nonsense. Let's take a look at the example to better understand it:

XML file ----- test. xml




127.0.0.1

pdo_msyql
localhsot
root
123

<Stag extends = "production">// Use the extends keyword to inherit from the node Production
<Database>
<Host> localhost <Username> root </username>
& Lt; password & gt; 123 & lt;/password & gt;
</Database>
</Stag>
</Config>

The PHP file for reading the data in the XML configuration file is as follows:

$ Filename = "test. xml ";

$ Section = "stag ";

$ Config = new zend_config_xml ($ filename, $ section );

 

Echo $ config-> webhost;

Echo $ config-> database-> type;

Here, the call is also a nested call of the object. Can we convert it to an array? Of course ~! Zend_config_xml is similar to zend_config_ini. You can also use the toarray () method to convert the read content to an array. The two methods are basically the same. If they are not, you can read the content of the previous section. If they are the same, I will not be embarrassed again.

In addition, when reading a file, the file to be read must be readable and exist, and no exception is thrown.

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.