Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
235

■ ■ ■


CHAPTER 16


Advanced Zend Framework


In the previous chapter, you got up and running with a really basic Zend Framework applica-
tion. It let you model a database, create a form, and validate data. The Zend Framework offers
a lot more.
This chapter provides details about how the framework actually works and introduces some of
its advanced features. You’ll learn how to use its facilities for configuration, debugging, routing,
caching, sending e-mail, creating PDF documents, and working with various web services.

Managing Configuration Files


Any reasonably complex application needs a set of configuration files. These files will hold
information like the database credentials the site is operating with, domain configuration data,
and other environment-related settings.
The Zend Framework, through the Zend_Config class, offers various ways of writing config-
uration data. We’ll look at the following approaches here:


  • Create a hierarchical array in your bootstrap file.

  • Create an INI file. The framework even allows you to extend sections and override keys
    when working with INIs.


•Use an XML file.

The Array Approach


To add a configuration array in your bootstrap file, simply create a key/value array. You can
nest arrays to create multiple-level hierarchies, too. When the Zend_Config class is instantiated
with an array, it will transform the array keys into properties, allowing for a very clean interface.
Listing 16-1 shows an example of using the array approach.

McArthur_819-9C16.fm Page 235 Friday, February 29, 2008 5:07 PM

Free download pdf