Zend Framework教程之Zend_Config_Xml用法分析
本文实例讲述了Zend Framework中Zend_Config_Xml用法。分享给大家供大家参考,具体如下: Zend_Config_Xml 让开发者能够存储配置数据到一个简单XML格式并通过嵌入对象属性语法来读
本文实例讲述了Zend Framework中Zend_Config_Xml用法。分享给大家供大家参考,具体如下:
Zend_Config_Xml 让开发者能够存储配置数据到一个简单XML格式并通过嵌入对象属性语法来读取。
XML文件的根元素(root element)不相关并可以任意命名。顶级的XML元素和配置数据的节相对应。
XML格式通过嵌入XML元素到节一级元素(section-level elements)的下面来支持等级结构组织。
叶一级(leaf-level)的XML元素和配置数据的值相对应。节继承通过一个特殊的XML属性名为extends来支持,与之相对应的这个属性的值通过扩展节(extending section)来继承.
返回类型
读入Zend_Config_Xml中的配置数据总是返回字串。数据从字符串到其它类型的转换留给开发者来适应他们特定的需求。
例: 使用Zend_Config_Xml
这个例子示例了从INI文件加载配置数据的Zend_Config_Xml的基本用法。在这个例子中有生产系统(production system)和开发系统(staging system)的配置数据。因为开发系统配置数据和生产系统的配置数据类似,所以开发系统的节从生产系统的节继承。在这个案例中,结果(decision)是任意的并且它可以反过来做,即生产系统节从开发系统节继承,尽管这不可能用于更复杂的情形。接着,假定下面的配置数据包含在/path/to/config.xml中:
<?xml version="1.0"?> <configdata> <production> <webhost>www.example.com</webhost> <database> <adapter>pdo_mysql</adapter> <params> <host>db.example.com</host> <username>dbuser</username> <password>secret</password> <dbname>dbname</dbname> </params> </database> </production> <staging extends="production"> <database> <params> <host>dev.example.com</host> <username>devuser</username> <password>devsecret</password> </params> </database> </staging> </configdata>
接着,假定开发者需要从XML文件取开发配置数据。这非常简单,只要指定XML文件和开发系统节就可以加载这些数据了:
$config = new Zend_Config_Xml('/path/to/config.xml', 'staging'); echo $config->database->params->host; // 输出 "dev.example.com" echo $config->database->params->dbname; // 输出 "dbname"
例 :在 Zend_Config_Xml 使用标签(tag)属性
Zend_Config_Xml 也支持另外两种方法在配置文件里定义节点。它们都利用属性。 因为 extends 和 value 属性是保留关键字(后者是第二种使用属性的方法),它们可能不被使用。 第一种方法使用属性是把属性添加到父节点,它本身就变成了子节点:
<?xml version="1.0"?> <configdata> <production webhost="www.example.com"> <database adapter="pdo_mysql"> <params host="db.example.com" username="dbuser" password="secret" dbname="dbname"/> </database> </production> <staging extends="production"> <database> <params host="dev.example.com" username="devuser" password="devsecret"/> </database> </staging> </configdata>
另一种方法也不会使配置文件变小,但使维护变得容易,是因为你需要要写标签名两次。你可以创建一个空标签,它在 value 属性里包含它的值:
<?xml version="1.0"?> <configdata> <production> <webhost>www.example.com</webhost> <database> <adapter value="pdo_mysql"/> <params> <host value="db.example.com"/> <username value="dbuser"/> <password value="secret"/> <dbname value="dbname"/> </params> </database> </production> <staging extends="production"> <database> <params> <host value="dev.example.com"/> <username value="devuser"/> <password value="devsecret"/> </params> </database> </staging> </configdata>
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Dewu APP is currently a very popular brand shopping software, but most users do not know how to use the functions in Dewu APP. The most detailed usage tutorial guide is compiled below. Next is the Dewuduo that the editor brings to users. A summary of function usage tutorials. Interested users can come and take a look! Tutorial on how to use Dewu [2024-03-20] How to use Dewu installment purchase [2024-03-20] How to obtain Dewu coupons [2024-03-20] How to find Dewu manual customer service [2024-03-20] How to check the pickup code of Dewu [2024-03-20] Where to find Dewu purchase [2024-03-20] How to open Dewu VIP [2024-03-20] How to apply for return or exchange of Dewu

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

PhotoshopCS is the abbreviation of Photoshop Creative Suite. It is a software produced by Adobe and is widely used in graphic design and image processing. As a novice learning PS, let me explain to you today what software photoshopcs5 is and how to use photoshopcs5. 1. What software is photoshop cs5? Adobe Photoshop CS5 Extended is ideal for professionals in film, video and multimedia fields, graphic and web designers who use 3D and animation, and professionals in engineering and scientific fields. Render a 3D image and merge it into a 2D composite image. Edit videos easily

With the continuous development of smart phones, the functions of mobile phones have become more and more powerful, among which the function of taking long pictures has become one of the important functions used by many users in daily life. Long screenshots can help users save a long web page, conversation record or picture at one time for easy viewing and sharing. Among many mobile phone brands, Huawei mobile phones are also one of the brands highly respected by users, and their function of cropping long pictures is also highly praised. This article will introduce you to the correct method of taking long pictures on Huawei mobile phones, as well as some expert tips to help you make better use of Huawei mobile phones.

PHP Tutorial: How to Convert Int Type to String In PHP, converting integer data to string is a common operation. This tutorial will introduce how to use PHP's built-in functions to convert the int type to a string, while providing specific code examples. Use cast: In PHP, you can use cast to convert integer data into a string. This method is very simple. You only need to add (string) before the integer data to convert it into a string. Below is a simple sample code

Honor mobile phones have always been favored by consumers because of their excellent performance and stable system. Recently, Honor mobile phones have released a new Hongmeng system, which has attracted the attention and expectations of many users. Hongmeng system is known as the system that "unifies the world". It has a smoother operating experience and higher security, allowing users to experience a new world of smartphones. Many users have expressed that they want to upgrade their Honor mobile phone system to the Hongmeng system. So, let’s take a look at the upgrade tutorial of the Honor mobile phone’s Hongmeng system. firstly, I

When using a computer to input English, sometimes we encounter the difference between full-width English letters and half-width English letters. Full-width English letters refer to the characters input by pressing the Shift key and the English letter key combination when the input method is Chinese mode. They occupy a full-width character width. Half-width English letters refer to characters input directly when the input method is English mode, and they occupy half a character width. In some cases, we may need to convert full-width English letters to half-width letters. Here is a simple tutorial: First, open a text editor or any
