• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Zend framework 1.10.x English
 

Zend framework 1.10.x English

on

  • 4,290 views

 

Statistics

Views

Total Views
4,290
Views on SlideShare
4,290
Embed Views
0

Actions

Likes
0
Downloads
13
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Zend framework 1.10.x English Zend framework 1.10.x English Document Transcript

    • Programmer's Reference Guide Zend Framework 1.10.x
    • Programmer's Reference Guide: Zend Framework 1.10.x Publication date 01/27/2010 by mikaelkael (SVN 20684) Copyright © 2005-2010 Zend Technologies Inc. (http://www.zend.com)
    • iii Table of Contents I. Introduction to Zend Framework .................................................................................... 1 Overview ................................................................................................................. 3 Installation ............................................................................................................... 4 II. Learning Zend Framework ........................................................................................... 5 Zend Framework Quick Start .................................................................................... 8 1. Zend Framework & MVC Introduction ........................................................... 8 1.1. Zend Framework ............................................................................... 8 1.2. Model-View-Controller ....................................................................... 8 2. Create Your Project ................................................................................... 10 2.1. Install Zend Framework ................................................................... 10 2.2. Create Your Project ......................................................................... 10 2.3. The Bootstrap ................................................................................. 11 2.4. Configuration ................................................................................... 12 2.5. Action Controllers ............................................................................ 12 2.6. Views ............................................................................................. 13 2.7. Checkpoint ...................................................................................... 15 3. Create A Layout ........................................................................................ 15 4. Create a Model and Database Table ........................................................... 18 5. Create A Form ........................................................................................... 28 6. Congratulations! ......................................................................................... 31 Autoloading in Zend Framework ............................................................................. 33 1. Introduction ................................................................................................ 33 2. Goals and Design ...................................................................................... 33 2.1. Class Naming Conventions .............................................................. 33 2.2. Autoloader Conventions and Design ................................................. 33 3. Basic Autoloader Usage ............................................................................. 34 4. Resource Autoloading ................................................................................ 36 5. Conclusion ................................................................................................. 37 Plugins in Zend Framework .................................................................................... 38 1. Introduction ................................................................................................ 38 2. Using Plugins ............................................................................................ 38 3. Conclusion ................................................................................................. 40 Getting Started with Zend_Layout ........................................................................... 42 1. Introduction ................................................................................................ 42 2. Using Zend_Layout .................................................................................... 42 2.1. Layout Configuration ....................................................................... 42 2.2. Create a Layout Script ..................................................................... 43 2.3. Accessing the Layout Object ............................................................ 43 2.4. Other Operations ............................................................................. 44 3. Zend_Layout: Conclusions .......................................................................... 45 Getting Started Zend_View Placeholders ................................................................. 46 1. Introduction ................................................................................................ 46 2. Basic Placeholder Usage ............................................................................ 46 3. Standard Placeholders ............................................................................... 49 3.1. Setting the DocType ........................................................................ 49 3.2. Specifying the Page Title ................................................................. 50 3.3. Specifying Stylesheets with HeadLink ............................................... 51 3.4. Aggregating Scripts Using HeadScript .............................................. 52 4. View Placeholders: Conclusion ................................................................... 54 Understanding and Using Zend Form Decorators ..................................................... 55 1. Introduction ................................................................................................ 55
    • Programmer's Reference Guide iv 2. Decorator Basics ....................................................................................... 55 2.1. Overview of the Decorator Pattern .................................................... 55 2.2. Creating Your First Decorator .......................................................... 57 3. Layering Decorators ................................................................................... 58 4. Rendering Individual Decorators ................................................................. 62 5. Creating and Rendering Composite Elements .............................................. 66 5.1. The Element ................................................................................... 66 5.2. The Decorator ................................................................................. 68 5.3. Conclusion ...................................................................................... 70 6. Conclusion ................................................................................................. 70 Getting Started with Zend_Session, Zend_Auth, and Zend_Acl ................................. 72 1. Building Multi-User Applications With Zend Framework ................................. 72 1.1. Zend Framework ............................................................................. 72 2. Managing User Sessions In ZF ................................................................... 72 2.1. Introduction to Sessions .................................................................. 72 2.2. Basic Usage of Zend_Session ......................................................... 73 2.3. Advanced Usage of Zend_Session ................................................... 74 3. Authenticating Users in Zend Framework .................................................... 74 3.1. Introduction to Authentication ........................................................... 74 3.2. Basic Usage of Zend_Auth .............................................................. 74 4. Building an Authorization System in Zend Framework ................................... 76 4.1. Introduction to Authorization ............................................................. 76 4.2. Basic Usage of Zend_Acl ................................................................ 77 Getting Started with Zend_Search_Lucene .............................................................. 80 1. Zend_Search_Lucene Introduction .............................................................. 80 2. Lucene Index Structure .............................................................................. 81 3. Index Opening and Creation ....................................................................... 82 4. Indexing .................................................................................................... 82 4.1. Indexing Policy ................................................................................ 82 5. Searching .................................................................................................. 83 6. Supported queries ...................................................................................... 84 7. Search result pagination ............................................................................. 86 Getting Started with Zend_Paginator ....................................................................... 88 1. Introduction ................................................................................................ 88 2. Simple Examples ....................................................................................... 88 3. Pagination Control and ScrollingStyles ........................................................ 90 4. Putting it all Together ................................................................................. 91 III. Zend Framework Reference ...................................................................................... 93 Zend_Acl ............................................................................................................. 124 1. Introduction .............................................................................................. 124 1.1. Resources ..................................................................................... 124 1.2. Roles ............................................................................................ 124 1.3. Creating the Access Control List .................................................... 125 1.4. Registering Roles .......................................................................... 126 1.5. Defining Access Controls ............................................................... 127 1.6. Querying an ACL .......................................................................... 127 2. Refining Access Controls .......................................................................... 128 2.1. Precise Access Controls ................................................................ 128 2.2. Removing Access Controls ............................................................ 130 3. Advanced Usage ...................................................................................... 130 3.1. Storing ACL Data for Persistence ................................................... 130 3.2. Writing Conditional ACL Rules with Assertions ................................ 131 Zend_Amf ............................................................................................................ 132 1. Introduction .............................................................................................. 132
    • Programmer's Reference Guide v 2. Zend_Amf_Server .................................................................................... 132 2.1. Connecting to the Server from Flex ................................................ 134 2.2. Error Handling ............................................................................... 136 2.3. AMF Responses ............................................................................ 136 2.4. Typed Objects ............................................................................... 136 2.5. Resources ..................................................................................... 138 2.6. Connecting to the Server from Flash ............................................... 138 2.7. Authentication ............................................................................... 140 Zend_Application .................................................................................................. 142 1. Introduction .............................................................................................. 142 2. Zend_Application Quick Start .................................................................... 142 2.1. Using Zend_Tool ........................................................................... 142 2.2. Adding Zend_Application to your application .................................... 144 2.3. Adding and creating resources ....................................................... 145 2.4. Next steps with Zend_Application ................................................... 147 3. Theory of Operation ................................................................................. 147 3.1. Bootstrapping ................................................................................ 148 3.2. Resource Plugins .......................................................................... 152 4. Examples ................................................................................................. 153 5. Core Functionality .................................................................................... 156 5.1. Zend_Application ........................................................................... 156 5.2. Zend_Application_Bootstrap_Bootstrapper ...................................... 159 5.3. Zend_Application_Bootstrap_ResourceBootstrapper ........................ 160 5.4. Zend_Application_Bootstrap_BootstrapAbstract ............................... 161 5.5. Zend_Application_Bootstrap_Bootstrap ........................................... 164 5.6. Zend_Application_Resource_Resource ........................................... 165 5.7. Zend_Application_Resource_ResourceAbstract ............................... 166 6. Available Resource Plugins ...................................................................... 168 6.1. Zend_Application_Resource_Cachemanager ................................... 168 6.2. Zend_Application_Resource_Db ..................................................... 168 6.3. Zend_Application_Resource_Frontcontroller .................................... 169 6.4. Zend_Application_Resource_Layout ............................................... 170 6.5. Zend_Application_Resource_Locale ............................................... 170 6.6. Zend_Application_Resource_Log .................................................... 171 6.7. Zend_Application_Resource_Mail ................................................... 172 6.8. Zend_Application_Resource_Modules ............................................. 172 6.9. Zend_Application_Resource_Multidb ............................................... 174 6.10. Zend_Application_Resource_Navigation ........................................ 175 6.11. Zend_Application_Resource_Router ............................................. 175 6.12. Zend_Application_Resource_Session ............................................ 176 6.13. Zend_Application_Resource_View ................................................ 176 Zend_Auth ........................................................................................................... 178 1. Introduction .............................................................................................. 178 1.1. Adapters ....................................................................................... 178 1.2. Results ......................................................................................... 179 1.3. Identity Persistence ....................................................................... 180 1.4. Usage ........................................................................................... 183 2. Database Table Authentication .................................................................. 184 2.1. Introduction ................................................................................... 184 2.2. Advanced Usage: Persisting a DbTable Result Object ...................... 186 2.3. Advanced Usage By Example ........................................................ 186 3. Digest Authentication ................................................................................ 188 3.1. Introduction ................................................................................... 188 3.2. Specifics ....................................................................................... 188
    • Programmer's Reference Guide vi 3.3. Identity .......................................................................................... 188 4. HTTP Authentication Adapter .................................................................... 189 4.1. Introduction ................................................................................... 189 4.2. Design Overview ........................................................................... 189 4.3. Configuration Options .................................................................... 189 4.4. Resolvers ...................................................................................... 190 4.5. Basic Usage ................................................................................. 191 5. LDAP Authentication ................................................................................ 192 5.1. Introduction ................................................................................... 192 5.2. Usage ........................................................................................... 192 5.3. The API ........................................................................................ 193 5.4. Server Options .............................................................................. 195 5.5. Collecting Debugging Messages ..................................................... 198 5.6. Common Options for Specific Servers ............................................. 199 6. Open ID Authentication ............................................................................ 200 6.1. Introduction ................................................................................... 200 6.2. Specifics ....................................................................................... 201 Zend_Barcode ..................................................................................................... 203 1. Introduction .............................................................................................. 203 2. Barcode creation using Zend_Barcode class .............................................. 203 2.1. Using Zend_Barcode::factory ......................................................... 203 2.2. Drawing a barcode ........................................................................ 204 2.3. Renderering a barcode .................................................................. 204 3. Zend_Barcode Objects ............................................................................. 205 3.1. Common Options .......................................................................... 206 3.2. Common Additional Getters ........................................................... 208 3.3. Description of shipped barcodes ..................................................... 208 4. Zend_Barcode Renderers ......................................................................... 215 4.1. Common Options .......................................................................... 215 4.2. Zend_Barcode_Renderer_Image .................................................... 216 4.3. Zend_Barcode_Renderer_Pdf ........................................................ 217 Zend_Cache ........................................................................................................ 218 1. Introduction .............................................................................................. 218 2. The Theory of Caching ............................................................................. 220 2.1. The Zend_Cache Factory Method ................................................... 221 2.2. Tagging Records ........................................................................... 221 2.3. Cleaning the Cache ....................................................................... 222 3. Zend_Cache Frontends ............................................................................ 222 3.1. Zend_Cache_Core ......................................................................... 222 3.2. Zend_Cache_Frontend_Output ....................................................... 226 3.3. Zend_Cache_Frontend_Function .................................................... 226 3.4. Zend_Cache_Frontend_Class ........................................................ 227 3.5. Zend_Cache_Frontend_File ........................................................... 229 3.6. Zend_Cache_Frontend_Page ......................................................... 229 4. Zend_Cache Backends ............................................................................. 234 4.1. Zend_Cache_Backend_File ............................................................ 234 4.2. Zend_Cache_Backend_Sqlite ......................................................... 235 4.3. Zend_Cache_Backend_Memcached ............................................... 236 4.4. Zend_Cache_Backend_Apc ........................................................... 237 4.5. Zend_Cache_Backend_Xcache ...................................................... 237 4.6. Zend_Cache_Backend_ZendPlatform ............................................. 237 4.7. Zend_Cache_Backend_TwoLevels ................................................. 238 4.8. Zend_Cache_Backend_ZendServer_Disk and Zend_Cache_Backend_ZendServer_ShMem ......................................... 239
    • Programmer's Reference Guide vii 5. The Cache Manager ................................................................................ 239 Zend_Captcha ..................................................................................................... 243 1. Introduction .............................................................................................. 243 2. Captcha Operation ................................................................................... 243 3. CAPTCHA Adapters ................................................................................. 244 3.1. Zend_Captcha_Word ..................................................................... 244 3.2. Zend_Captcha_Dumb .................................................................... 245 3.3. Zend_Captcha_Figlet ..................................................................... 245 3.4. Zend_Captcha_Image .................................................................... 245 3.5. Zend_Captcha_ReCaptcha ............................................................ 246 Zend_CodeGenerator ........................................................................................... 247 1. Introduction .............................................................................................. 247 1.1. Theory of Operation ...................................................................... 247 2. Zend_CodeGenerator Examples ............................................................... 249 3. Zend_CodeGenerator Reference ............................................................... 253 3.1. Abstract Classes and Interfaces ..................................................... 253 3.2. Concrete CodeGenerator Classes .................................................. 255 Zend_Config ........................................................................................................ 261 1. Introduction .............................................................................................. 261 2. Theory of Operation ................................................................................. 262 3. Zend_Config_Ini ....................................................................................... 263 4. Zend_Config_Xml ..................................................................................... 265 Zend_Config_Writer .............................................................................................. 270 1. Zend_Config_Writer .................................................................................. 270 Zend_Console_Getopt .......................................................................................... 273 1. Introduction .............................................................................................. 273 2. Declaring Getopt Rules ............................................................................ 274 2.1. Declaring Options with the Short Syntax ......................................... 274 2.2. Declaring Options with the Long Syntax .......................................... 274 3. Fetching Options and Arguments .............................................................. 275 3.1. Handling Getopt Exceptions ........................................................... 275 3.2. Fetching Options by Name ............................................................. 276 3.3. Reporting Options ......................................................................... 276 3.4. Fetching Non-option Arguments ..................................................... 277 4. Configuring Zend_Console_Getopt ............................................................ 277 4.1. Adding Option Rules ...................................................................... 277 4.2. Adding Help Messages .................................................................. 277 4.3. Adding Option Aliases ................................................................... 278 4.4. Adding Argument Lists ................................................................... 278 4.5. Adding Configuration ..................................................................... 279 Zend_Controller ................................................................................................... 281 1. Zend_Controller Quick Start ...................................................................... 281 1.1. Introduction ................................................................................... 281 1.2. Quick Start .................................................................................... 281 2. Zend_Controller Basics ............................................................................. 284 3. The Front Controller ................................................................................. 287 3.1. Overview ....................................................................................... 287 3.2. Primary Methods ........................................................................... 288 3.3. Environmental Accessor Methods ................................................... 289 3.4. Front Controller Parameters ........................................................... 291 3.5. Extending the Front Controller ........................................................ 291 4. The Request Object ................................................................................. 292 4.1. Introduction ................................................................................... 292 4.2. HTTP Requests ............................................................................. 292
    • Programmer's Reference Guide viii 4.3. Subclassing the Request Object ..................................................... 295 5. The Standard Router ................................................................................ 297 5.1. Introduction ................................................................................... 297 5.2. Using a Router .............................................................................. 298 5.3. Basic Rewrite Router Operation ..................................................... 298 5.4. Default Routes .............................................................................. 300 5.5. Base URL and Subdirectories ........................................................ 301 5.6. Global Parameters ......................................................................... 301 5.7. Route Types ................................................................................. 301 5.8. Using Zend_Config with the RewriteRouter ..................................... 314 5.9. Subclassing the Router .................................................................. 315 6. The Dispatcher ........................................................................................ 315 6.1. Overview ....................................................................................... 315 6.2. Subclassing the Dispatcher ............................................................ 317 7. Action Controllers ..................................................................................... 320 7.1. Introduction ................................................................................... 320 7.2. Object Initialization ........................................................................ 321 7.3. Pre- and Post-Dispatch Hooks ....................................................... 321 7.4. Accessors ..................................................................................... 322 7.5. View Integration ............................................................................ 323 7.6. Utility Methods .............................................................................. 324 7.7. Subclassing the Action Controller ................................................... 325 8. Action Helpers ......................................................................................... 327 8.1. Introduction ................................................................................... 327 8.2. Helper Initialization ........................................................................ 327 8.3. The Helper Broker ......................................................................... 328 8.4. Built-in Action Helpers ................................................................... 329 8.5. Writing Your Own Helpers .............................................................. 357 9. The Response Object ............................................................................... 357 9.1. Usage ........................................................................................... 357 9.2. Manipulating Headers .................................................................... 359 9.3. Named Segments .......................................................................... 360 9.4. Testing for Exceptions in the Response Object ................................ 361 9.5. Subclassing the Response Object .................................................. 362 10. Plugins .................................................................................................. 362 10.1. Introduction ................................................................................. 362 10.2. Writing Plugins ............................................................................ 362 10.3. Using Plugins .............................................................................. 363 10.4. Retrieving and Manipulating Plugins ............................................. 364 10.5. Plugins Included in the Standard Distribution ................................. 364 11. Using a Conventional Modular Directory Structure .................................... 369 11.1. Introduction ................................................................................. 369 11.2. Specifying Module Controller Directories ....................................... 370 11.3. Routing to Modules ...................................................................... 371 11.4. Module or Global Default Controller .............................................. 371 12. MVC Exceptions ..................................................................................... 371 12.1. Introduction ................................................................................. 371 12.2. Handling Exceptions .................................................................... 372 12.3. MVC Exceptions You May Encounter ............................................ 373 Zend_Currency .................................................................................................... 376 1. Introduction to Zend_Currency .................................................................. 376 1.1. Why should you use Zend_Currency? ............................................. 376 2. Using Zend_Currency ............................................................................... 376 2.1. Generic usage ............................................................................... 376
    • Programmer's Reference Guide ix 2.2. Currency creation based on a locale ............................................... 377 3. Options for currencies .............................................................................. 377 4. What makes a currency? .......................................................................... 378 5. Where is the currency? ............................................................................ 380 6. How does the currency look like? .............................................................. 381 7. How much is my currency? ...................................................................... 382 7.1. Working with currency values ......................................................... 383 7.2. Using precision on currencies ........................................................ 383 8. Calculating with currencies ....................................................................... 384 9. Exchanging currencies ............................................................................. 385 10. Additional informations on Zend_Currency ............................................... 386 10.1. Currency informations .................................................................. 386 10.2. Currency Performance Optimization .............................................. 387 Zend_Date ........................................................................................................... 388 1. Introduction .............................................................................................. 388 1.1. Always Set a Default Timezone ...................................................... 388 1.2. Why Use Zend_Date? ................................................................... 388 2. Theory of Operation ................................................................................. 389 2.1. Internals ........................................................................................ 389 3. Basic Methods ......................................................................................... 390 3.1. Current Date ................................................................................. 390 3.2. Zend_Date by Example ................................................................. 390 4. Zend_Date API Overview ......................................................................... 392 4.1. Zend_Date Options ....................................................................... 392 4.2. Working with Date Values .............................................................. 393 4.3. Basic Zend_Date Operations Common to Many Date Parts .............. 394 4.4. Comparing Dates .......................................................................... 397 4.5. Getting Dates and Date Parts ........................................................ 399 4.6. Working with Fractions of Seconds ................................................. 400 4.7. Sunrise / Sunset ............................................................................ 400 5. Creation of Dates ..................................................................................... 401 5.1. Create the Actual Date .................................................................. 401 5.2. Create a Date from Database ........................................................ 401 5.3. Create Dates from an Array ........................................................... 402 6. Constants for General Date Functions ....................................................... 402 6.1. Using Constants ............................................................................ 402 6.2. List of All Constants ...................................................................... 403 6.3. Self-Defined OUTPUT Formats with ISO ......................................... 407 6.4. Self-Defined OUTPUT Formats Using PHP's date() Format Specifiers ............................................................................................. 410 7. Working Examples ................................................................................... 413 7.1. Checking Dates ............................................................................. 413 7.2. Sunrise and Sunset ....................................................................... 414 7.3. Time Zones ................................................................................... 416 Zend_Db .............................................................................................................. 419 1. Zend_Db_Adapter .................................................................................... 419 1.1. Connecting to a Database Using an Adapter ................................... 419 1.2. Example Database ........................................................................ 424 1.3. Reading Query Results .................................................................. 425 1.4. Writing Changes to the Database ................................................... 428 1.5. Quoting Values and Identifiers ........................................................ 432 1.6. Controlling Database Transactions ................................................. 434 1.7. Listing and Describing Tables ........................................................ 435 1.8. Closing a Connection .................................................................... 436
    • Programmer's Reference Guide x 1.9. Running Other Database Statements .............................................. 437 1.10. Retrieving Server Version ............................................................. 438 1.11. Notes on Specific Adapters .......................................................... 438 2. Zend_Db_Statement ................................................................................. 441 2.1. Creating a Statement ..................................................................... 441 2.2. Executing a Statement ................................................................... 442 2.3. Fetching Results from a SELECT Statement ................................... 442 3. Zend_Db_Profiler ..................................................................................... 444 3.1. Introduction ................................................................................... 444 3.2. Using the Profiler .......................................................................... 446 3.3. Advanced Profiler Usage ............................................................... 447 3.4. Specialized Profilers ...................................................................... 448 4. Zend_Db_Select ....................................................................................... 449 4.1. Introduction ................................................................................... 449 4.2. Creating a Select Object ................................................................ 450 4.3. Building Select queries .................................................................. 450 4.4. Executing Select Queries ............................................................... 463 4.5. Other methods .............................................................................. 464 5. Zend_Db_Table ....................................................................................... 466 5.1. Introduction ................................................................................... 466 5.2. Using Zend_Db_Table as a concrete class ...................................... 466 5.3. Defining a Table Class .................................................................. 466 5.4. Creating an Instance of a Table ..................................................... 469 5.5. Inserting Rows to a Table .............................................................. 471 5.6. Updating Rows in a Table .............................................................. 473 5.7. Deleting Rows from a Table ........................................................... 473 5.8. Finding Rows by Primary Key ........................................................ 474 5.9. Querying for a Set of Rows ............................................................ 475 5.10. Querying for a Single Row ........................................................... 479 5.11. Retrieving Table Metadata Information .......................................... 479 5.12. Caching Table Metadata .............................................................. 480 5.13. Customizing and Extending a Table Class ..................................... 482 6. Zend_Db_Table_Row ............................................................................... 485 6.1. Introduction ................................................................................... 485 6.2. Fetching a Row ............................................................................. 485 6.3. Writing rows to the database .......................................................... 487 6.4. Serializing and unserializing rows ................................................... 489 6.5. Extending the Row class ............................................................... 490 7. Zend_Db_Table_Rowset ........................................................................... 493 7.1. Introduction ................................................................................... 493 7.2. Fetching a Rowset ........................................................................ 493 7.3. Retrieving Rows from a Rowset ..................................................... 493 7.4. Retrieving a Rowset as an Array .................................................... 495 7.5. Serializing and Unserializing a Rowset ............................................ 496 7.6. Extending the Rowset class ........................................................... 497 8. Zend_Db_Table Relationships ................................................................... 498 8.1. Introduction ................................................................................... 498 8.2. Defining Relationships ................................................................... 498 8.3. Fetching a Dependent Rowset ....................................................... 500 8.4. Fetching a Parent Row .................................................................. 502 8.5. Fetching a Rowset via a Many-to-many Relationship ........................ 503 8.6. Cascading Write Operations ........................................................... 505 9. Zend_Db_Table_Definition ........................................................................ 507 9.1. Introduction ................................................................................... 507
    • Programmer's Reference Guide xi 9.2. Basic Usage ................................................................................. 507 9.3. Advanced Usage ........................................................................... 509 Zend_Debug ........................................................................................................ 511 1. Dumping Variables ................................................................................... 511 Zend_Dojo ........................................................................................................... 512 1. Introduction .............................................................................................. 512 2. Zend_Dojo_Data: dojo.data Envelopes ...................................................... 512 2.1. Zend_Dojo_Data Usage ................................................................. 512 2.2. Adding metadata to your containers ................................................ 514 2.3. Advanced Use Cases .................................................................... 514 3. Dojo View Helpers ................................................................................... 516 3.1. dojo() View Helper ......................................................................... 516 3.2. Dijit-Specific View Helpers ............................................................. 521 4. Dojo Form Elements and Decorators ......................................................... 534 4.1. Dijit-Specific Form Decorators ........................................................ 535 4.2. Dijit-Specific Form Elements ........................................................... 537 4.3. Dojo Form Examples ..................................................................... 554 5. Zend_Dojo build layer support .................................................................. 555 5.1. Introduction ................................................................................... 555 5.2. Generating Custom Module Layers with Zend_Dojo_BuildLayer ........ 556 5.3. Generating Build Profiles with Zend_Dojo_BuildLayer ...................... 558 Zend_Dom ........................................................................................................... 561 1. Introduction .............................................................................................. 561 2. Zend_Dom_Query .................................................................................... 561 2.1. Theory of Operation ...................................................................... 561 2.2. Methods Available ......................................................................... 562 Zend_Exception ................................................................................................... 564 1. Using Exceptions ..................................................................................... 564 2. Basic usage ............................................................................................. 564 3. Previous Exceptions ................................................................................. 564 Zend_Feed .......................................................................................................... 566 1. Introduction .............................................................................................. 566 2. Importing Feeds ....................................................................................... 567 2.1. Custom feeds ................................................................................ 567 3. Retrieving Feeds from Web Pages ............................................................ 571 4. Consuming an RSS Feed ......................................................................... 572 5. Consuming an Atom Feed ........................................................................ 573 6. Consuming a Single Atom Entry ............................................................... 574 7. Modifying Feed and Entry structures ......................................................... 575 8. Custom Feed and Entry Classes ............................................................... 575 9. Zend_Feed_Reader .................................................................................. 577 9.1. Introduction ................................................................................... 577 9.2. Importing Feeds ............................................................................ 577 9.3. Retrieving Underlying Feed and Entry Sources ................................ 578 9.4. Cache Support and Intelligent Requests ......................................... 579 9.5. Locating Feed URIs from Websites ................................................. 580 9.6. Attribute Collections ....................................................................... 581 9.7. Retrieving Feed Information ........................................................... 582 9.8. Retrieving Entry/Item Information .................................................... 585 9.9. Extending Feed and Entry APIs ...................................................... 588 10. Zend_Feed_Writer .................................................................................. 592 10.1. Introduction ................................................................................. 592 10.2. Architecture ................................................................................. 592 10.3. Getting Started ............................................................................ 593
    • Programmer's Reference Guide xii 10.4. Setting Feed Data Points ............................................................. 594 10.5. Setting Entry Data Points ............................................................. 596 11. Zend_Feed_Pubsubhubbub .................................................................... 598 11.1. What is Pubsubhubbub? .............................................................. 598 11.2. Architecture ................................................................................. 599 11.3. Zend_Feed_Pubsubhubbub_Publisher .......................................... 599 11.4. Zend_Feed_Pubsubhubbub_Subscriber ........................................ 600 Zend_File ............................................................................................................ 608 1. Zend_File_Transfer .................................................................................. 608 1.1. Supported Adapters for Zend_File_Transfer .................................... 609 1.2. Options for Zend_File_Transfer ...................................................... 609 1.3. Checking Files .............................................................................. 610 1.4. Additional File Informations ............................................................ 610 1.5. Progress for file uploads ................................................................ 612 2. Validators for Zend_File_Transfer .............................................................. 614 2.1. Using Validators with Zend_File_Transfer ........................................ 615 2.2. Count Validator ............................................................................. 617 2.3. Crc32 Validator ............................................................................. 618 2.4. ExcludeExtension Validator ............................................................ 618 2.5. ExcludeMimeType Validator ........................................................... 619 2.6. Exists Validator ............................................................................. 620 2.7. Extension Validator ........................................................................ 620 2.8. FilesSize Validator ......................................................................... 621 2.9. ImageSize Validator ....................................................................... 622 2.10. IsCompressed Validator ............................................................... 623 2.11. IsImage Validator ......................................................................... 623 2.12. Hash Validator ............................................................................. 624 2.13. Md5 Validator .............................................................................. 624 2.14. MimeType Validator ..................................................................... 625 2.15. NotExists Validator ...................................................................... 626 2.16. Sha1 Validator ............................................................................. 627 2.17. Size Validator .............................................................................. 627 2.18. WordCount Validator .................................................................... 628 3. Filters for Zend_File_Transfer ................................................................... 628 3.1. Using filters with Zend_File_Transfer .............................................. 629 3.2. Decrypt filter .................................................................................. 630 3.3. Encrypt filter .................................................................................. 630 3.4. LowerCase filter ............................................................................ 631 3.5. Rename filter ................................................................................ 631 3.6. UpperCase filter ............................................................................ 632 Zend_Filter .......................................................................................................... 634 1. Introduction .............................................................................................. 634 1.1. What is a filter? ............................................................................. 634 1.2. Basic usage of filters ..................................................................... 634 1.3. Using the static staticFilter() method ............................................... 634 2. Standard Filter Classes ............................................................................ 635 2.1. Alnum ........................................................................................... 635 2.2. Alpha ............................................................................................ 636 2.3. BaseName .................................................................................... 636 2.4. Boolean ........................................................................................ 636 2.5. Callback ........................................................................................ 638 2.6. Compress and Decompress ........................................................... 639 2.7. Decrypt ......................................................................................... 645 2.8. Digits ............................................................................................ 647
    • Programmer's Reference Guide xiii 2.9. Dir ................................................................................................ 647 2.10. Encrypt ....................................................................................... 647 2.11. HtmlEntities ................................................................................. 650 2.12. Int ............................................................................................... 650 2.13. LocalizedToNormalized ................................................................ 650 2.14. NormalizedToLocalized ................................................................ 651 2.15. Null ............................................................................................. 653 2.16. PregReplace ............................................................................... 654 2.17. RealPath ..................................................................................... 655 2.18. StringToLower ............................................................................. 655 2.19. StringToUpper ............................................................................. 656 2.20. StringTrim ................................................................................... 656 2.21. StripNewlines .............................................................................. 656 2.22. StripTags .................................................................................... 656 3. Filter Chains ............................................................................................ 656 3.1. Changing filter chain order ............................................................. 657 4. Writing Filters ........................................................................................... 657 5. Zend_Filter_Input ..................................................................................... 658 5.1. Declaring Filter and Validator Rules ................................................ 658 5.2. Creating the Filter and Validator Processor ..................................... 660 5.3. Retrieving Validated Fields and other Reports ................................. 660 5.4. Using Metacommands to Control Filter or Validator Rules ................. 663 5.5. Adding Filter Class Namespaces .................................................... 668 6. Zend_Filter_Inflector ................................................................................. 669 6.1. Operation ...................................................................................... 669 6.2. Setting Paths To Alternate Filters ................................................... 670 6.3. Setting the Inflector Target ............................................................. 670 6.4. Inflection Rules ............................................................................. 671 6.5. Utility Methods .............................................................................. 673 6.6. Using Zend_Config with Zend_Filter_Inflector .................................. 673 Zend_Form .......................................................................................................... 675 1. Zend_Form .............................................................................................. 675 2. Zend_Form Quick Start ............................................................................ 675 2.1. Create a form object ...................................................................... 675 2.2. Add elements to the form ............................................................... 675 2.3. Render a form ............................................................................... 677 2.4. Check if a form is valid .................................................................. 678 2.5. Get error status ............................................................................. 679 2.6. Putting it together .......................................................................... 679 2.7. Using a Zend_Config Object .......................................................... 681 2.8. Conclusion .................................................................................... 682 3. Creating Form Elements Using Zend_Form_Element .................................. 682 3.1. Plugin Loaders .............................................................................. 682 3.2. Filters ........................................................................................... 684 3.3. Validators ...................................................................................... 685 3.4. Decorators .................................................................................... 690 3.5. Metadata and Attributes ................................................................. 692 3.6. Standard Elements ........................................................................ 693 3.7. Zend_Form_Element Methods ........................................................ 693 3.8. Configuration ................................................................................. 695 3.9. Custom Elements .......................................................................... 696 4. Creating Forms Using Zend_Form ............................................................ 697 4.1. Plugin Loaders .............................................................................. 698 4.2. Elements ....................................................................................... 699
    • Programmer's Reference Guide xiv 4.3. Display Groups ............................................................................. 703 4.4. Sub Forms .................................................................................... 707 4.5. Metadata and Attributes ................................................................. 708 4.6. Decorators .................................................................................... 709 4.7. Validation ...................................................................................... 711 4.8. Methods ........................................................................................ 713 4.9. Configuration ................................................................................. 716 4.10. Custom forms .............................................................................. 717 5. Creating Custom Form Markup Using Zend_Form_Decorator ...................... 719 5.1. Operation ...................................................................................... 719 5.2. Standard Decorators ...................................................................... 720 5.3. Custom Decorators ........................................................................ 720 5.4. Rendering Individual Decorators ..................................................... 723 6. Standard Form Elements Shipped With Zend Framework ............................ 723 6.1. Zend_Form_Element_Button .......................................................... 723 6.2. Zend_Form_Element_Captcha ....................................................... 723 6.3. Zend_Form_Element_Checkbox ..................................................... 724 6.4. Zend_Form_Element_File .............................................................. 725 6.5. Zend_Form_Element_Hidden ......................................................... 728 6.6. Zend_Form_Element_Hash ............................................................ 728 6.7. Zend_Form_Element_Image .......................................................... 728 6.8. Zend_Form_Element_MultiCheckbox .............................................. 728 6.9. Zend_Form_Element_Multiselect .................................................... 729 6.10. Zend_Form_Element_Password ................................................... 730 6.11. Zend_Form_Element_Radio ......................................................... 730 6.12. Zend_Form_Element_Reset ......................................................... 730 6.13. Zend_Form_Element_Select ......................................................... 731 6.14. Zend_Form_Element_Submit ........................................................ 731 6.15. Zend_Form_Element_Text ........................................................... 731 6.16. Zend_Form_Element_Textarea ..................................................... 732 7. Standard Form Decorators Shipped With Zend Framework ......................... 732 7.1. Zend_Form_Decorator_Callback ..................................................... 732 7.2. Zend_Form_Decorator_Captcha ..................................................... 732 7.3. Zend_Form_Decorator_Description ................................................. 732 7.4. Zend_Form_Decorator_DtDdWrapper ............................................. 733 7.5. Zend_Form_Decorator_Errors ........................................................ 733 7.6. Zend_Form_Decorator_Fieldset ...................................................... 733 7.7. Zend_Form_Decorator_File ............................................................ 733 7.8. Zend_Form_Decorator_Form .......................................................... 733 7.9. Zend_Form_Decorator_FormElements ............................................ 733 7.10. Zend_Form_Decorator_FormErrors ............................................... 734 7.11. Zend_Form_Decorator_HtmlTag ................................................... 734 7.12. Zend_Form_Decorator_Image ...................................................... 734 7.13. Zend_Form_Decorator_Label ....................................................... 735 7.14. Zend_Form_Decorator_PrepareElements ...................................... 735 7.15. Zend_Form_Decorator_ViewHelper ............................................... 735 7.16. Zend_Form_Decorator_ViewScript ................................................ 736 8. Internationalization of Zend_Form ............................................................. 737 8.1. Initializing I18n in Forms ................................................................ 737 8.2. Standard I18n Targets ................................................................... 738 9. Advanced Zend_Form Usage .................................................................... 739 9.1. Array Notation ............................................................................... 739 9.2. Multi-Page Forms .......................................................................... 741 Zend_Gdata ......................................................................................................... 743
    • Programmer's Reference Guide xv 1. Introduction .............................................................................................. 743 1.1. Structure of Zend_Gdata ................................................................ 743 1.2. Interacting with Google Services .................................................... 744 1.3. Obtaining instances of Zend_Gdata classes .................................... 744 1.4. Google Data Client Authentication .................................................. 745 1.5. Dependencies ............................................................................... 745 1.6. Creating a new Gdata client ........................................................... 745 1.7. Common Query Parameters ........................................................... 746 1.8. Fetching a Feed ............................................................................ 747 1.9. Working with Multi-page Feeds ...................................................... 747 1.10. Working with Data in Feeds and Entries ........................................ 748 1.11. Updating Entries .......................................................................... 748 1.12. Posting Entries to Google Servers ................................................ 749 1.13. Deleting Entries on Google Servers .............................................. 749 2. Authenticating with AuthSub ..................................................................... 750 2.1. Creating an AuthSub authenticated Http Client ................................ 750 2.2. Revoking AuthSub authentication ................................................... 751 3. Using the Book Search Data API .............................................................. 751 3.1. Authenticating to the Book Search service ...................................... 752 3.2. Searching for books ...................................................................... 752 3.3. Using community features .............................................................. 753 3.4. Book collections and My Library ..................................................... 755 4. Authenticating with ClientLogin .................................................................. 757 4.1. Creating a ClientLogin authenticated Http Client .............................. 757 4.2. Terminating a ClientLogin authenticated Http Client ......................... 758 5. Using Google Calendar ............................................................................ 758 5.1. Connecting To The Calendar Service ............................................. 758 5.2. Retrieving A Calendar List ............................................................. 761 5.3. Retrieving Events .......................................................................... 761 5.4. Creating Events ............................................................................. 763 5.5. Modifying Events ........................................................................... 766 5.6. Deleting Events ............................................................................. 767 5.7. Accessing Event Comments ........................................................... 767 6. Using Google Documents List Data API .................................................... 768 6.1. Get a List of Documents ................................................................ 768 6.2. Upload a Document ....................................................................... 768 6.3. Searching the documents feed ....................................................... 769 7. Using Google Health ................................................................................ 770 7.1. Connect To The Health Service ...................................................... 770 7.2. Profile Feed .................................................................................. 773 7.3. Profile List Feed ............................................................................ 774 7.4. Sending Notices to the Register Feed ............................................. 775 8. Using Google Spreadsheets ..................................................................... 776 8.1. Create a Spreadsheet .................................................................... 776 8.2. Get a List of Spreadsheets ............................................................ 776 8.3. Get a List of Worksheets ............................................................... 776 8.4. Interacting With List-based Feeds ................................................... 776 8.5. Interacting With Cell-based Feeds .................................................. 779 9. Using Google Apps Provisioning ............................................................... 780 9.1. Setting the current domain ............................................................. 780 9.2. Interacting with users ..................................................................... 781 9.3. Interacting with nicknames ............................................................. 784 9.4. Interacting with email lists .............................................................. 786 9.5. Interacting with email list recipients ................................................. 787
    • Programmer's Reference Guide xvi 9.6. Handling errors ............................................................................. 788 10. Using Google Base ................................................................................ 788 10.1. Connect To The Base Service ...................................................... 789 10.2. Retrieve Items ............................................................................. 791 10.3. Insert, Update, and Delete Customer Items ................................... 793 11. Using Picasa Web Albums ...................................................................... 794 11.1. Connecting To The Service .......................................................... 795 11.2. Understanding and Constructing Queries ...................................... 797 11.3. Retrieving Feeds And Entries ....................................................... 798 11.4. Creating Entries ........................................................................... 802 11.5. Deleting Entries ........................................................................... 803 12. Using the YouTube Data API .................................................................. 805 12.1. Authentication .............................................................................. 805 12.2. Developer Keys and Client ID ...................................................... 805 12.3. Retrieving public video feeds ........................................................ 805 12.4. Retrieving video comments .......................................................... 807 12.5. Retrieving playlist feeds ............................................................... 808 12.6. Retrieving a list of a user's subscriptions ....................................... 808 12.7. Retrieving a user's profile ............................................................. 809 12.8. Uploading Videos to YouTube ...................................................... 809 12.9. Browser-based upload ................................................................. 811 12.10. Checking upload status .............................................................. 811 12.11. Other Functions ......................................................................... 812 13. Catching Gdata Exceptions ..................................................................... 812 Zend_Http ............................................................................................................ 814 1. Introduction .............................................................................................. 814 1.1. Using Zend_Http_Client ................................................................. 814 1.2. Configuration Parameters ............................................................... 814 1.3. Performing Basic HTTP Requests .................................................. 815 1.4. Adding GET and POST parameters ............................................... 816 1.5. Accessing Last Request and Response .......................................... 817 2. Zend_Http_Client - Advanced Usage ......................................................... 817 2.1. HTTP Redirections ........................................................................ 817 2.2. Adding Cookies and Using Cookie Persistence ................................ 817 2.3. Setting Custom Request Headers ................................................... 818 2.4. File Uploads .................................................................................. 819 2.5. Sending Raw POST Data .............................................................. 820 2.6. HTTP Authentication ...................................................................... 820 2.7. Sending Multiple Requests With the Same Client ............................. 821 2.8. Data Streaming ............................................................................. 822 3. Zend_Http_Client - Connection Adapters ................................................... 823 3.1. Overview ....................................................................................... 823 3.2. The Socket Adapter ....................................................................... 823 3.3. The Proxy Adapter ........................................................................ 826 3.4. The cURL Adapter ........................................................................ 827 3.5. The Test Adapter .......................................................................... 828 3.6. Creating your own connection adapters .......................................... 831 4. Zend_Http_Cookie and Zend_Http_CookieJar ............................................ 833 4.1. Introduction ................................................................................... 833 4.2. Instantiating Zend_Http_Cookie Objects .......................................... 833 4.3. Zend_Http_Cookie getter methods .................................................. 834 4.4. Zend_Http_Cookie: Matching against a scenario .............................. 835 4.5. The Zend_Http_CookieJar Class: Instantiation ................................. 836 4.6. Adding Cookies to a Zend_Http_CookieJar object ............................ 837
    • Programmer's Reference Guide xvii 4.7. Retrieving Cookies From a Zend_Http_CookieJar object .................. 837 5. Zend_Http_Response ............................................................................... 838 5.1. Introduction ................................................................................... 838 5.2. Boolean Tester Methods ................................................................ 839 5.3. Accessor Methods ......................................................................... 839 5.4. Static HTTP Response Parsers ...................................................... 840 Zend_InfoCard ..................................................................................................... 842 1. Introduction .............................................................................................. 842 1.1. Basic Theory of Usage .................................................................. 842 1.2. Using as part of Zend_Auth ........................................................... 842 1.3. Using the Zend_InfoCard component standalone ............................. 844 1.4. Working with a Claims object ......................................................... 844 1.5. Attaching Information Cards to existing accounts ............................. 845 1.6. Creating Zend_InfoCard Adapters ................................................... 846 Zend_Json ........................................................................................................... 848 1. Introduction .............................................................................................. 848 2. Basic Usage ............................................................................................ 848 2.1. Pretty-printing JSON ...................................................................... 848 3. Advanced Usage of Zend_Json ................................................................ 848 3.1. JSON Objects ............................................................................... 848 3.2. Encoding PHP objects ................................................................... 849 3.3. Internal Encoder/Decoder ............................................................... 849 3.4. JSON Expressions ........................................................................ 849 4. XML to JSON conversion ......................................................................... 850 5. Zend_Json_Server - JSON-RPC server ..................................................... 851 5.1. Advanced Details .......................................................................... 854 Zend_Layout ........................................................................................................ 860 1. Introduction .............................................................................................. 860 2. Zend_Layout Quick Start .......................................................................... 860 2.1. Layout scripts ................................................................................ 860 2.2. Using Zend_Layout with the Zend Framework MVC ......................... 861 2.3. Using Zend_Layout as a Standalone Component ............................. 862 2.4. Sample Layout .............................................................................. 863 3. Zend_Layout Configuration Options ........................................................... 865 3.1. Examples ...................................................................................... 865 4. Zend_Layout Advanced Usage ................................................................. 867 4.1. Custom View Objects .................................................................... 867 4.2. Custom Front Controller Plugins ..................................................... 867 4.3. Custom Action Helpers .................................................................. 868 4.4. Custom Layout Script Path Resolution: Using the Inflector ................ 868 Zend_Ldap .......................................................................................................... 870 1. Introduction .............................................................................................. 870 1.1. Theory of operation ....................................................................... 870 2. API overview ........................................................................................... 873 2.1. Configuration / options ................................................................... 873 2.2. API Reference ............................................................................... 875 3. Usage Scenarios ...................................................................................... 900 3.1. Authentication scenarios ................................................................ 900 3.2. Basic CRUD operations ................................................................. 901 3.3. Extended operations ...................................................................... 902 4. Tools ....................................................................................................... 903 4.1. Creation and modification of DN strings .......................................... 903 4.2. Using the filter API to create search filters ....................................... 903 4.3. Modify LDAP entries using the Attribute API .................................... 903
    • Programmer's Reference Guide xviii 5. Object oriented access to the LDAP tree using Zend_Ldap_Node ................ 903 5.1. Basic CRUD operations ................................................................. 903 5.2. Extended operations ...................................................................... 904 5.3. Tree traversal ................................................................................ 904 6. Getting information from the LDAP server .................................................. 904 6.1. RootDSE ....................................................................................... 904 6.2. Schema Browsing ......................................................................... 904 7. Serializing LDAP data to and from LDIF .................................................... 905 7.1. Serialize a LDAP entry to LDIF ...................................................... 905 7.2. Deserialize a LDIF string into a LDAP entry ..................................... 906 Zend_Loader ....................................................................................................... 908 1. Loading Files and Classes Dynamically ..................................................... 908 1.1. Loading Files ................................................................................ 908 1.2. Loading Classes ............................................................................ 908 1.3. Testing if a File is Readable ........................................................... 909 1.4. Using the Autoloader ..................................................................... 910 2. The Autoloader ........................................................................................ 910 2.1. Using the Autoloader ..................................................................... 911 2.2. Selecting a Zend Framework version .............................................. 912 2.3. The Autoloader Interface ................................................................ 914 2.4. Autoloader Reference .................................................................... 914 3. Resource Autoloaders .............................................................................. 917 3.1. Resource autoloader usage ........................................................... 917 3.2. The Module Resource Autoloader ................................................... 919 3.3. Using Resource Autoloaders as Object Factories ............................. 919 3.4. Resource Autoloader Reference ..................................................... 919 4. Loading Plugins ....................................................................................... 919 4.1. Basic Use Case ............................................................................ 920 4.2. Manipulating Plugin Paths .............................................................. 921 4.3. Testing for Plugins and Retrieving Class Names .............................. 921 4.4. Getting Better Performance for Plugins ........................................... 922 Zend_Locale ........................................................................................................ 923 1. Introduction .............................................................................................. 923 1.1. What is Localization ...................................................................... 923 1.2. What is a Locale? ......................................................................... 924 1.3. How are Locales Represented? ...................................................... 924 1.4. Selecting the Right Locale ............................................................. 925 1.5. Usage of automatic Locales ........................................................... 925 1.6. Using a default Locale ................................................................... 926 1.7. ZF Locale-Aware Classes .............................................................. 927 1.8. Application wide locale .................................................................. 927 1.9. Zend_Locale_Format::setOptions(array $options) ............................ 928 1.10. Speed up Zend_Locale and its subclasses .................................... 928 2. Using Zend_Locale .................................................................................. 929 2.1. Copying, Cloning, and Serializing Locale Objects ............................. 929 2.2. Equality ......................................................................................... 929 2.3. Default locales .............................................................................. 930 2.4. Set a new locale ........................................................................... 930 2.5. Getting the language and region .................................................... 930 2.6. Obtaining localized strings ............................................................. 931 2.7. Obtaining translations for "yes" and "no" ......................................... 945 2.8. Get a list of all known locales ........................................................ 946 2.9. Detecting locales ........................................................................... 946 3. Normalization and Localization .................................................................. 948
    • Programmer's Reference Guide xix 3.1. Number normalization: getNumber($input, Array $options) ................ 948 3.2. Number localization ....................................................................... 949 3.3. Number testing .............................................................................. 951 3.4. Float value normalization ............................................................... 951 3.5. Floating point value localization ...................................................... 951 3.6. Floating point value testing ............................................................ 951 3.7. Integer value normalization ............................................................ 952 3.8. Integer point value localization ....................................................... 952 3.9. Integer value testing ...................................................................... 952 3.10. Numeral System Conversion ........................................................ 952 4. Working with Dates and Times ................................................................. 954 4.1. Normalizing Dates and Times ........................................................ 954 4.2. Testing Dates ................................................................................ 957 4.3. Normalizing a Time ....................................................................... 958 4.4. Testing Times ............................................................................... 958 5. Supported locales .................................................................................... 958 Zend_Log ............................................................................................................ 970 1. Overview ................................................................................................. 970 1.1. Creating a Log .............................................................................. 970 1.2. Logging Messages ........................................................................ 970 1.3. Destroying a Log ........................................................................... 971 1.4. Using Built-in Priorities ................................................................... 971 1.5. Adding User-defined Priorities ........................................................ 971 1.6. Understanding Log Events ............................................................. 972 2. Writers ..................................................................................................... 972 2.1. Writing to Streams ......................................................................... 972 2.2. Writing to Databases ..................................................................... 973 2.3. Writing to Firebug .......................................................................... 973 2.4. Writing to Email ............................................................................. 975 2.5. Writing to the System Log .............................................................. 977 2.6. Writing to the Zend Server Monitor ................................................. 978 2.7. Stubbing Out the Writer ................................................................. 982 2.8. Testing with the Mock .................................................................... 982 2.9. Compositing Writers ...................................................................... 982 3. Formatters ............................................................................................... 983 3.1. Simple Formatting ......................................................................... 983 3.2. Formatting to XML ......................................................................... 983 4. Filters ...................................................................................................... 984 4.1. Filtering for All Writers ................................................................... 984 4.2. Filtering for a Writer Instance ......................................................... 985 5. Using the Factory to Create a Log ............................................................ 985 5.1. Writer Options ............................................................................... 986 5.2. Filter Options ................................................................................ 987 5.3. Creating Configurable Writers and Filters ........................................ 987 Zend_Mail ............................................................................................................ 989 1. Introduction .............................................................................................. 989 1.1. Getting started .............................................................................. 989 1.2. Configuring the default sendmail transport ....................................... 989 2. Sending via SMTP ................................................................................... 990 3. Sending Multiple Mails per SMTP Connection ............................................ 990 4. Using Different Transports ........................................................................ 992 5. HTML E-Mail ........................................................................................... 992 6. Attachments ............................................................................................. 993 7. Adding Recipients .................................................................................... 994
    • Programmer's Reference Guide xx 8. Controlling the MIME Boundary ................................................................. 994 9. Additional Headers ................................................................................... 994 10. Character Sets ....................................................................................... 995 11. Encoding ............................................................................................... 995 12. SMTP Authentication .............................................................................. 996 13. Securing SMTP Transport ....................................................................... 996 14. Reading Mail Messages .......................................................................... 997 14.1. Simple example using Pop3 ......................................................... 997 14.2. Opening a local storage ............................................................... 997 14.3. Opening a remote storage ............................................................ 998 14.4. Fetching messages and simple methods ....................................... 998 14.5. Working with messages ............................................................... 999 14.6. Checking for flags ...................................................................... 1001 14.7. Using folders ............................................................................. 1002 14.8. Advanced Use ........................................................................... 1004 Zend_Markup ..................................................................................................... 1008 1. Introduction ............................................................................................ 1008 2. Getting Started With Zend_Markup .......................................................... 1008 3. Zend_Markup Parsers ............................................................................ 1009 3.1. Theory of Parsing ........................................................................ 1009 3.2. The BBCode parser ..................................................................... 1009 3.3. The Textile parser ....................................................................... 1010 4. Zend_Markup Renderers ........................................................................ 1010 4.1. Adding your own tags .................................................................. 1011 4.2. List of tags .................................................................................. 1012 Zend_Measure ................................................................................................... 1013 1. Introduction ............................................................................................ 1013 2. Creation of Measurements ...................................................................... 1013 2.1. Creating measurements from integers and floats ............................ 1013 2.2. Creating measurements from strings ............................................. 1014 2.3. Measurements from localized strings ............................................ 1014 3. Outputting measurements ....................................................................... 1015 3.1. Automatic output ......................................................................... 1015 3.2. Outputting values ......................................................................... 1015 3.3. Output with unit of measurement .................................................. 1016 3.4. Output as localized string ............................................................. 1016 4. Manipulating Measurements .................................................................... 1016 4.1. Convert ....................................................................................... 1016 4.2. Add and subtract ......................................................................... 1017 4.3. Compare ..................................................................................... 1017 4.4. Compare ..................................................................................... 1018 4.5. Manually change values ............................................................... 1018 4.6. Manually change types ................................................................ 1019 5. Types of measurements ......................................................................... 1019 5.1. Hints for Zend_Measure_Binary .................................................... 1022 5.2. Hints for Zend_Measure_Number ................................................. 1022 5.3. Roman numbers .......................................................................... 1022 Zend_Memory .................................................................................................... 1023 1. Overview ............................................................................................... 1023 1.1. Introduction ................................................................................. 1023 1.2. Theory of Operation ..................................................................... 1023 2. Memory Manager ................................................................................... 1024 2.1. Creating a Memory Manager ........................................................ 1024 2.2. Managing Memory Objects ........................................................... 1025
    • Programmer's Reference Guide xxi 2.3. Memory Manager Settings ........................................................... 1026 3. Memory Objects ..................................................................................... 1026 3.1. Movable ...................................................................................... 1026 3.2. Locked ........................................................................................ 1027 3.3. Memory container 'value' property ................................................. 1027 3.4. Memory container interface .......................................................... 1027 Zend_Mime ........................................................................................................ 1030 1. Zend_Mime ............................................................................................ 1030 1.1. Introduction ................................................................................. 1030 1.2. Static Methods and Constants ...................................................... 1030 1.3. Instantiating Zend_Mime .............................................................. 1031 2. Zend_Mime_Message ............................................................................. 1031 2.1. Introduction ................................................................................. 1031 2.2. Instantiation ................................................................................. 1031 2.3. Adding MIME Parts ...................................................................... 1031 2.4. Boundary handling ....................................................................... 1031 2.5. parsing a string to create a Zend_Mime_Message object (experimental) .................................................................................... 1032 3. Zend_Mime_Part .................................................................................... 1032 3.1. Introduction ................................................................................. 1032 3.2. Instantiation ................................................................................. 1032 3.3. Methods for rendering the message part to a string ........................ 1032 Zend_Navigation ................................................................................................ 1034 1. Introduction ............................................................................................ 1034 1.1. Pages and Containers ................................................................. 1034 1.2. Separation of data (model) and rendering (view) ............................ 1034 2. Pages .................................................................................................... 1034 2.1. Common page features ................................................................ 1035 2.2. Zend_Navigation_Page_Mvc ........................................................ 1037 2.3. Zend_Navigation_Page_Uri .......................................................... 1041 2.4. Creating custom page types ......................................................... 1042 2.5. Creating pages using the page factory .......................................... 1043 3. Containers ............................................................................................. 1045 3.1. Creating containers ...................................................................... 1045 3.2. Adding pages .............................................................................. 1048 3.3. Removing pages ......................................................................... 1048 3.4. Finding pages ............................................................................. 1049 3.5. Iterating containers ...................................................................... 1051 3.6. Other operations .......................................................................... 1051 Zend_Oauth ....................................................................................................... 1054 1. Introduction to OAuth ............................................................................. 1054 1.1. Protocol Workflow ........................................................................ 1054 1.2. Security Architecture .................................................................... 1055 1.3. Getting Started ............................................................................ 1056 Zend_OpenId ..................................................................................................... 1060 1. Introduction ............................................................................................ 1060 1.1. What is OpenID? ......................................................................... 1060 1.2. How Does it Work? ..................................................................... 1060 1.3. Zend_OpenId Structure ................................................................ 1061 1.4. Supported OpenID Standards ....................................................... 1061 2. Zend_OpenId_Consumer Basics ............................................................. 1061 2.1. OpenID Authentication ................................................................. 1061 2.2. Combining all Steps in One Page ................................................. 1063 2.3. Consumer Realm ......................................................................... 1063
    • Programmer's Reference Guide xxii 2.4. Immediate Check ......................................................................... 1064 2.5. Zend_OpenId_Consumer_Storage ................................................ 1064 2.6. Simple Registration Extension ...................................................... 1067 2.7. Integration with Zend_Auth ........................................................... 1068 2.8. Integration with Zend_Controller ................................................... 1070 3. Zend_OpenId_Provider ........................................................................... 1070 3.1. Quick Start .................................................................................. 1070 3.2. Combined Provide Scripts ............................................................ 1073 3.3. Simple Registration Extension ...................................................... 1074 3.4. Anything Else? ............................................................................ 1076 Zend_Paginator .................................................................................................. 1077 1. Introduction ............................................................................................ 1077 2. Usage .................................................................................................... 1077 2.1. Paginating data collections ........................................................... 1077 2.2. The DbSelect and DbTableSelect adapter ..................................... 1078 2.3. Rendering pages with view scripts ................................................ 1079 3. Configuration .......................................................................................... 1083 4. Advanced usage .................................................................................... 1084 4.1. Custom data source adapters ....................................................... 1084 4.2. Custom scrolling styles ................................................................ 1084 4.3. Caching features ......................................................................... 1085 4.4. Zend_Paginator_AdapterAggregate Interface ................................. 1086 Zend_Pdf ........................................................................................................... 1087 1. Introduction ............................................................................................ 1087 2. Creating and Loading PDF Documents .................................................... 1087 3. Save Changes to PDF Documents .......................................................... 1088 4. Working with Pages ................................................................................ 1088 4.1. Page Creation ............................................................................. 1088 4.2. Page cloning ............................................................................... 1089 5. Drawing ................................................................................................. 1090 5.1. Geometry .................................................................................... 1090 5.2. Colors ......................................................................................... 1090 5.3. Shape Drawing ............................................................................ 1091 5.4. Text Drawing ............................................................................... 1093 5.5. Using fonts .................................................................................. 1094 5.6. Standard PDF fonts limitations ..................................................... 1096 5.7. Extracting fonts ........................................................................... 1097 5.8. Image Drawing ............................................................................ 1099 5.9. Line drawing style ........................................................................ 1099 5.10. Fill style .................................................................................... 1100 5.11. Linear Transformations ............................................................... 1101 5.12. Save/restore graphics state ........................................................ 1102 5.13. Clipping draw area ..................................................................... 1102 5.14. Styles ........................................................................................ 1103 5.15. Transparency ............................................................................. 1106 6. Interactive Features ................................................................................ 1106 6.1. Destinations ................................................................................ 1106 6.2. Actions ........................................................................................ 1111 6.3. Document Outline (bookmarks) ..................................................... 1113 6.4. Annotations ................................................................................. 1115 7. Document Info and Metadata .................................................................. 1116 8. Zend_Pdf module usage example ........................................................... 1118 Zend_ProgressBar .............................................................................................. 1120 1. Zend_ProgressBar .................................................................................. 1120
    • Programmer's Reference Guide xxiii 1.1. Introduction ................................................................................. 1120 1.2. Basic Usage of Zend_Progressbar ................................................ 1120 1.3. Persistent progress ...................................................................... 1120 1.4. Standard adapters ....................................................................... 1120 Zend_Queue ...................................................................................................... 1125 1. Introduction ............................................................................................ 1125 2. Example usage ...................................................................................... 1125 3. Framework ............................................................................................. 1126 3.1. Introduction ................................................................................. 1127 3.2. Commonality among adapters ...................................................... 1127 4. Adapters ................................................................................................ 1127 4.1. Specific Adapters - Configuration settings ...................................... 1128 4.2. Notes for Specific Adapters .......................................................... 1130 5. Customizing Zend_Queue ....................................................................... 1132 5.1. Creating your own adapter ........................................................... 1132 5.2. Creating your own message class ................................................ 1133 5.3. Creating your own message iterator class ..................................... 1134 5.4. Creating your own queue class ................................................... 1134 6. Stomp .................................................................................................... 1134 6.1. Stomp - Supporting classes .......................................................... 1134 Zend_Reflection ................................................................................................. 1135 1. Introduction ............................................................................................ 1135 2. Zend_Reflection Examples ...................................................................... 1135 3. Zend_Reflection Reference ..................................................................... 1136 3.1. Zend_Reflection_Docblock ........................................................... 1137 3.2. Zend_Reflection_Docblock_Tag .................................................... 1137 3.3. Zend_Reflection_Docblock_Tag_Param ........................................ 1137 3.4. Zend_Reflection_Docblock_Tag_Return ........................................ 1138 3.5. Zend_Reflection_File ................................................................... 1138 3.6. Zend_Reflection_Class ................................................................ 1138 3.7. Zend_Reflection_Extension .......................................................... 1139 3.8. Zend_Reflection_Function ............................................................ 1139 3.9. Zend_Reflection_Method .............................................................. 1139 3.10. Zend_Reflection_Parameter ........................................................ 1139 3.11. Zend_Reflection_Property .......................................................... 1140 Zend_Registry .................................................................................................... 1141 1. Using the Registry .................................................................................. 1141 1.1. Setting Values in the Registry ...................................................... 1141 1.2. Getting Values from the Registry .................................................. 1141 1.3. Constructing a Registry Object ..................................................... 1141 1.4. Accessing the Registry as an Array .............................................. 1142 1.5. Accessing the Registry as an Object ............................................. 1142 1.6. Querying if an Index Exists .......................................................... 1143 1.7. Extending the Registry ................................................................. 1143 1.8. Unsetting the Static Registry ........................................................ 1144 Zend_Rest ......................................................................................................... 1145 1. Introduction ............................................................................................ 1145 2. Zend_Rest_Client ................................................................................... 1145 2.1. Introduction ................................................................................. 1145 2.2. Responses .................................................................................. 1145 2.3. Request Arguments ..................................................................... 1147 3. Zend_Rest_Server .................................................................................. 1148 3.1. Introduction ................................................................................. 1148 3.2. REST Server Usage .................................................................... 1148
    • Programmer's Reference Guide xxiv 3.3. Calling a Zend_Rest_Server Service ............................................. 1149 3.4. Sending A Custom Status ............................................................ 1149 3.5. Returning Custom XML Responses .............................................. 1149 Zend_Search_Lucene ......................................................................................... 1151 1. Overview ............................................................................................... 1151 1.1. Introduction ................................................................................. 1151 1.2. Document and Field Objects ........................................................ 1151 1.3. Understanding Field Types ........................................................... 1152 1.4. HTML documents ........................................................................ 1153 1.5. Word 2007 documents ................................................................. 1154 1.6. Powerpoint 2007 documents ........................................................ 1155 1.7. Excel 2007 documents ................................................................. 1156 2. Building Indexes ..................................................................................... 1157 2.1. Creating a New Index .................................................................. 1157 2.2. Updating Index ............................................................................ 1158 2.3. Updating Documents ................................................................... 1158 2.4. Retrieving Index Size ................................................................... 1158 2.5. Index optimization ........................................................................ 1159 2.6. Permissions ................................................................................. 1160 2.7. Limitations ................................................................................... 1160 3. Searching an Index ................................................................................ 1161 3.1. Building Queries .......................................................................... 1161 3.2. Search Results ............................................................................ 1162 3.3. Limiting the Result Set ................................................................. 1163 3.4. Results Scoring ........................................................................... 1163 3.5. Search Result Sorting .................................................................. 1164 3.6. Search Results Highlighting .......................................................... 1164 4. Query Language .................................................................................... 1166 4.1. Terms ......................................................................................... 1167 4.2. Fields .......................................................................................... 1167 4.3. Wildcards .................................................................................... 1168 4.4. Term Modifiers ............................................................................ 1168 4.5. Range Searches .......................................................................... 1168 4.6. Fuzzy Searches ........................................................................... 1169 4.7. Matched terms limitation .............................................................. 1169 4.8. Proximity Searches ...................................................................... 1169 4.9. Boosting a Term .......................................................................... 1169 4.10. Boolean Operators ..................................................................... 1170 4.11. Grouping ................................................................................... 1171 4.12. Field Grouping ........................................................................... 1172 4.13. Escaping Special Characters ...................................................... 1172 5. Query Construction API .......................................................................... 1172 5.1. Query Parser Exceptions ............................................................. 1172 5.2. Term Query ................................................................................. 1173 5.3. Multi-Term Query ......................................................................... 1173 5.4. Boolean Query ............................................................................ 1174 5.5. Wildcard Query ........................................................................... 1176 5.6. Fuzzy Query ............................................................................... 1176 5.7. Phrase Query .............................................................................. 1177 5.8. Range Query ............................................................................... 1179 6. Character Set ......................................................................................... 1180 6.1. UTF-8 and single-byte character set support ................................. 1180 6.2. Default text analyzer .................................................................... 1180 6.3. UTF-8 compatible text analyzers ................................................... 1181
    • Programmer's Reference Guide xxv 7. Extensibility ............................................................................................ 1182 7.1. Text Analysis ............................................................................... 1182 7.2. Tokens Filtering ........................................................................... 1184 7.3. Scoring Algorithms ....................................................................... 1185 7.4. Storage Containers ...................................................................... 1186 8. Interoperating with Java Lucene .............................................................. 1188 8.1. File Formats ................................................................................ 1188 8.2. Index Directory ............................................................................ 1189 8.3. Java Source Code ....................................................................... 1189 9. Advanced ............................................................................................... 1189 9.1. Starting from 1.6, handling index format transformations ................. 1189 9.2. Using the index as static property ................................................. 1190 10. Best Practices ...................................................................................... 1191 10.1. Field names .............................................................................. 1191 10.2. Indexing performance ................................................................. 1192 10.3. Index during Shut Down ............................................................. 1194 10.4. Retrieving documents by unique id ............................................. 1194 10.5. Memory Usage .......................................................................... 1195 10.6. Encoding ................................................................................... 1195 10.7. Index maintenance ..................................................................... 1196 Zend_Serializer .................................................................................................. 1198 1. Introduction ............................................................................................ 1198 1.1. Using the Zend_Serializer static interface ...................................... 1198 2. Zend_Serializer_Adapter ......................................................................... 1199 2.1. Zend_Serializer_Adapter_PhpSerialize .......................................... 1199 2.2. Zend_Serializer_Adapter_Igbinary ................................................. 1199 2.3. Zend_Serializer_Adapter_Wddx .................................................... 1199 2.4. Zend_Serializer_Adapter_Json ..................................................... 1200 2.5. Zend_Serializer_Adapter_Amf 0 and 3 .......................................... 1200 2.6. Zend_Serializer_Adapter_PythonPickle ......................................... 1200 2.7. Zend_Serializer_Adapter_PhpCode ............................................... 1201 Zend_Server ...................................................................................................... 1202 1. Introduction ............................................................................................ 1202 2. Zend_Server_Reflection .......................................................................... 1202 2.1. Introduction ................................................................................. 1202 2.2. Usage ......................................................................................... 1202 Zend_Service ..................................................................................................... 1204 1. Introduction ............................................................................................ 1204 2. Zend_Service_Akismet ........................................................................... 1204 2.1. Introduction ................................................................................. 1204 2.2. Verify an API key ........................................................................ 1205 2.3. Check for spam ........................................................................... 1205 2.4. Submitting known spam ............................................................... 1206 2.5. Submitting false positives (ham) ................................................... 1206 2.6. Zend-specific Methods ................................................................. 1207 3. Zend_Service_Amazon ........................................................................... 1207 3.1. Introduction ................................................................................. 1207 3.2. Country Codes ............................................................................ 1208 3.3. Looking up a Specific Amazon Item by ASIN ................................. 1209 3.4. Performing Amazon Item Searches ............................................... 1209 3.5. Using the Alternative Query API ................................................... 1210 3.6. Zend_Service_Amazon Classes ................................................... 1210 4. Zend_Service_Amazon_Ec2 ................................................................... 1215 4.1. Introduction ................................................................................. 1215
    • Programmer's Reference Guide xxvi 4.2. What is Amazon Ec2? ................................................................. 1215 4.3. Static Methods ............................................................................ 1215 5. Zend_Service_Amazon_Ec2: Instances ................................................... 1216 5.1. Instance Types ............................................................................ 1216 5.2. Running Amazon EC2 Instances .................................................. 1217 5.3. Amazon Instance Utilities ............................................................. 1219 6. Zend_Service_Amazon_Ec2: Windows Instances ..................................... 1221 6.1. Windows Instances Usage ........................................................... 1222 7. Zend_Service_Amazon_Ec2: Reserved Instances .................................... 1222 7.1. How Reserved Instances are Applied ............................................ 1222 7.2. Reserved Instances Usage ........................................................... 1223 8. Zend_Service_Amazon_Ec2: CloudWatch Monitoring ............................... 1224 8.1. CloudWatch Usage ...................................................................... 1224 9. Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI) ................... 1226 9.1. AMI Information Utilities ............................................................... 1226 9.2. AMI Attribute Utilities ................................................................... 1227 10. Zend_Service_Amazon_Ec2: Elastic Block Stroage (EBS) ....................... 1228 10.1. Create EBS Volumes and Snapshots .......................................... 1229 10.2. Describing EBS Volumes and Snapshots .................................... 1229 10.3. Attach and Detaching Volumes from Instances ............................ 1230 10.4. Deleting EBS Volumes and Snapshots ........................................ 1231 11. Zend_Service_Amazon_Ec2: Elastic IP Addresses ................................. 1231 12. Zend_Service_Amazon_Ec2: Keypairs ................................................... 1232 13. Zend_Service_Amazon_Ec2: Regions and Availability Zones ................... 1233 13.1. Amazon EC2 Regions ................................................................ 1233 13.2. Amazon EC2 Availability Zones .................................................. 1234 14. Zend_Service_Amazon_Ec2: Security Groups ........................................ 1234 14.1. Security Group Maintenance ....................................................... 1234 14.2. Authorizing Access .................................................................... 1235 14.3. Revoking Access ....................................................................... 1236 15. Zend_Service_Amazon_S3 ................................................................... 1237 15.1. Introduction ............................................................................... 1237 15.2. Registering with Amazon S3 ....................................................... 1237 15.3. API Documentation .................................................................... 1237 15.4. Features .................................................................................... 1237 15.5. Getting Started .......................................................................... 1237 15.6. Bucket operations ...................................................................... 1238 15.7. Object operations ....................................................................... 1239 15.8. Data Streaming ......................................................................... 1241 15.9. Stream wrapper ......................................................................... 1241 16. Zend_Service_Amazon_Sqs .................................................................. 1242 16.1. Introduction ............................................................................... 1242 16.2. Registering with Amazon SQS .................................................... 1242 16.3. API Documentation .................................................................... 1242 16.4. Features .................................................................................... 1242 16.5. Getting Started .......................................................................... 1242 16.6. Queue operations ...................................................................... 1243 16.7. Message operations ................................................................... 1244 17. Zend_Service_Audioscrobbler ............................................................... 1244 17.1. Introduction ............................................................................... 1244 17.2. Users ........................................................................................ 1245 17.3. Artists ........................................................................................ 1246 17.4. Tracks ....................................................................................... 1247 17.5. Tags ......................................................................................... 1247
    • Programmer's Reference Guide xxvii 17.6. Groups ...................................................................................... 1247 17.7. Forums ...................................................................................... 1248 18. Zend_Service_Delicious ........................................................................ 1248 18.1. Introduction ............................................................................... 1248 18.2. Retrieving posts ......................................................................... 1248 18.3. Zend_Service_Delicious_PostList ................................................ 1249 18.4. Editing posts ............................................................................. 1250 18.5. Deleting posts ........................................................................... 1251 18.6. Adding new posts ...................................................................... 1251 18.7. Tags ......................................................................................... 1251 18.8. Bundles ..................................................................................... 1252 18.9. Public data ................................................................................ 1252 18.10. HTTP client ............................................................................. 1253 19. Zend_Service_DeveloperGarden ........................................................... 1253 19.1. Introduction to DeveloperGarden ................................................. 1253 19.2. BaseUserService ....................................................................... 1254 19.3. IP Location ................................................................................ 1256 19.4. Local Search ............................................................................. 1256 19.5. Send SMS ................................................................................. 1256 19.6. SMS Validation .......................................................................... 1257 19.7. Voice Call ................................................................................. 1257 19.8. ConferenceCall .......................................................................... 1258 19.9. Performance and Caching .......................................................... 1260 20. Zend_Service_Flickr ............................................................................. 1260 20.1. Introduction ............................................................................... 1260 20.2. Finding Flickr Users' Photos and Information ............................... 1260 20.3. Finding photos From a Group Pool ............................................. 1261 20.4. Retrieving Flickr Image Details ................................................... 1261 20.5. Zend_Service_Flickr Result Classes ........................................... 1262 21. Zend_Service_LiveDocx ........................................................................ 1264 21.1. Introduction to LiveDocx ............................................................. 1264 21.2. Zend_Service_LiveDocx_MailMerge ............................................ 1265 22. Zend_Service_Nirvanix ......................................................................... 1278 22.1. Introduction ............................................................................... 1278 22.2. Registering with Nirvanix ............................................................ 1278 22.3. API Documentation .................................................................... 1278 22.4. Features .................................................................................... 1279 22.5. Getting Started .......................................................................... 1279 22.6. Understanding the Proxy ............................................................ 1280 22.7. Examining Results ..................................................................... 1280 22.8. Handling Errors ......................................................................... 1281 23. Zend_Service_ReCaptcha ..................................................................... 1282 23.1. Introduction ............................................................................... 1282 23.2. Simplest use ............................................................................. 1282 23.3. Hiding email addresses .............................................................. 1283 24. Zend_Service_Simpy ............................................................................ 1284 24.1. Introduction ............................................................................... 1284 24.2. Links ......................................................................................... 1285 24.3. Tags ......................................................................................... 1286 24.4. Notes ........................................................................................ 1287 24.5. Watchlists .................................................................................. 1288 25. Introduction .......................................................................................... 1289 25.1. Getting Started with Zend_Service_SlideShare ............................ 1289 25.2. The SlideShow object ................................................................ 1290
    • Programmer's Reference Guide xxviii 25.3. Retrieving a single slide show .................................................... 1292 25.4. Retrieving Groups of Slide Shows ............................................... 1292 25.5. Zend_Service_SlideShare Caching policies ................................. 1293 25.6. Changing the behavior of the HTTP Client ................................... 1294 26. Zend_Service_StrikeIron ....................................................................... 1294 26.1. Overview ................................................................................... 1294 26.2. Registering with StrikeIron .......................................................... 1295 26.3. Getting Started .......................................................................... 1295 26.4. Making Your First Query ............................................................ 1295 26.5. Examining Results ..................................................................... 1296 26.6. Handling Errors ......................................................................... 1297 26.7. Checking Your Subscription ........................................................ 1297 27. Zend_Service_StrikeIron: Bundled Services ........................................... 1298 27.1. ZIP Code Information ................................................................. 1298 27.2. U.S. Address Verification ............................................................ 1299 27.3. Sales & Use Tax Basic .............................................................. 1300 28. Zend_Service_StrikeIron: Advanced Uses .............................................. 1300 28.1. Using Services by WSDL ........................................................... 1300 28.2. Viewing SOAP Transactions ....................................................... 1301 29. Zend_Service_Technorati ...................................................................... 1301 29.1. Introduction ............................................................................... 1301 29.2. Getting Started .......................................................................... 1302 29.3. Making Your First Query ............................................................ 1302 29.4. Consuming Results .................................................................... 1303 29.5. Handling Errors ......................................................................... 1304 29.6. Checking Your API Key Daily Usage ........................................... 1304 29.7. Available Technorati Queries ...................................................... 1305 29.8. Zend_Service_Technorati Classes .............................................. 1308 30. Zend_Service_Twitter ........................................................................... 1311 30.1. Introduction ............................................................................... 1311 30.2. Authentication ............................................................................ 1312 30.3. Account Methods ....................................................................... 1312 30.4. Status Methods ......................................................................... 1313 30.5. User Methods ............................................................................ 1315 30.6. Direct Message Methods ............................................................ 1315 30.7. Friendship Methods ................................................................... 1316 30.8. Favorite Methods ....................................................................... 1317 30.9. Block Methods ........................................................................... 1317 30.10. Zend_Service_Twitter_Search ................................................... 1318 31. Zend_Service_WindowsAzure ............................................................... 1320 31.1. Introduction ............................................................................... 1320 31.2. Installing the Windows Azure SDK .............................................. 1320 31.3. API Documentation .................................................................... 1320 31.4. Features .................................................................................... 1320 31.5. Architecture ............................................................................... 1320 31.6. Zend_Service_WindowsAzure_Storage_Blob ............................... 1320 31.7. Zend_Service_WindowsAzure_Storage_Table ............................. 1325 31.8. Zend_Service_WindowsAzure_Storage_Queue ............................ 1332 32. Zend_Service_Yahoo ............................................................................ 1334 32.1. Introduction ............................................................................... 1334 32.2. Searching the Web with Yahoo! .................................................. 1334 32.3. Finding Images with Yahoo! ....................................................... 1335 32.4. Finding videos with Yahoo! ......................................................... 1335 32.5. Finding Local Businesses and Services with Yahoo! ..................... 1335
    • Programmer's Reference Guide xxix 32.6. Searching Yahoo! News ............................................................. 1335 32.7. Searching Yahoo! Site Explorer Inbound Links ............................. 1336 32.8. Searching Yahoo! Site Explorer's PageData ................................ 1336 32.9. Zend_Service_Yahoo Classes .................................................... 1336 Zend_Session .................................................................................................... 1343 1. Introduction ............................................................................................ 1343 2. Basic Usage .......................................................................................... 1343 2.1. Tutorial Examples ........................................................................ 1344 2.2. Iterating Over Session Namespaces ............................................. 1345 2.3. Accessors for Session Namespaces ............................................. 1345 3. Advanced Usage .................................................................................... 1345 3.1. Starting a Session ....................................................................... 1345 3.2. Locking Session Namespaces ...................................................... 1346 3.3. Namespace Expiration ................................................................. 1347 3.4. Session Encapsulation and Controllers ......................................... 1347 3.5. Preventing Multiple Instances per Namespace ............................... 1348 3.6. Working with Arrays ..................................................................... 1349 3.7. Using Sessions with Objects ........................................................ 1350 3.8. Using Sessions with Unit Tests .................................................... 1350 4. Global Session Management .................................................................. 1351 4.1. Configuration Options .................................................................. 1352 4.2. Error: Headers Already Sent ........................................................ 1355 4.3. Session Identifiers ....................................................................... 1355 4.4. rememberMe(integer $seconds) ................................................... 1357 4.5. forgetMe() ................................................................................... 1357 4.6. sessionExists() ............................................................................ 1357 4.7. destroy(bool $remove_cookie = true, bool $readonly = true) ............ 1357 4.8. stop() .......................................................................................... 1357 4.9. writeClose($readonly = true) ......................................................... 1358 4.10. expireSessionCookie() ................................................................ 1358 4.11. setSaveHandler(Zend_Session_SaveHandler_Interface $interface) ........................................................................................................... 1358 4.12. namespaceIsset($namespace) .................................................... 1358 4.13. namespaceUnset($namespace) .................................................. 1358 4.14. namespaceGet($namespace) ..................................................... 1359 4.15. getIterator() ............................................................................... 1359 5. Zend_Session_SaveHandler_DbTable ..................................................... 1359 Zend_Soap ........................................................................................................ 1362 1. Zend_Soap_Server ................................................................................. 1362 1.1. Zend_Soap_Server constructor ..................................................... 1362 1.2. Methods to define Web Service API .............................................. 1363 1.3. Request and response objects handling ........................................ 1364 2. Zend_Soap_Client .................................................................................. 1365 2.1. Zend_Soap_Client Constructor ..................................................... 1366 2.2. Performing SOAP Requests ......................................................... 1367 3. WSDL Accessor ..................................................................................... 1368 3.1. Zend_Soap_Wsdl constructor ....................................................... 1368 3.2. addMessage() method ................................................................. 1368 3.3. addPortType() method ................................................................. 1369 3.4. addPortOperation() method .......................................................... 1369 3.5. addBinding() method .................................................................... 1369 3.6. addBindingOperation() method ..................................................... 1370 3.7. addSoapBinding() method ............................................................ 1370 3.8. addSoapOperation() method ......................................................... 1370
    • Programmer's Reference Guide xxx 3.9. addService() method .................................................................... 1370 3.10. Type mapping ........................................................................... 1371 3.11. addDocumentation() method ....................................................... 1372 3.12. Get finalized WSDL document .................................................... 1373 4. AutoDiscovery ........................................................................................ 1373 4.1. AutoDiscovery Introduction ........................................................... 1373 4.2. Class autodiscovering .................................................................. 1374 4.3. Functions autodiscovering ............................................................ 1375 4.4. Autodiscovering Datatypes ........................................................... 1376 4.5. WSDL Binding Styles ................................................................... 1376 Zend_Tag .......................................................................................................... 1377 1. Introduction ............................................................................................ 1377 2. Zend_Tag_Cloud .................................................................................... 1377 2.1. Decorators .................................................................................. 1378 Zend_Test .......................................................................................................... 1380 1. Introduction ............................................................................................ 1380 2. Zend_Test_PHPUnit ............................................................................... 1380 2.1. Bootstrapping your TestCase ....................................................... 1382 2.2. Testing your Controllers and MVC Applications .............................. 1383 2.3. Assertions ................................................................................... 1385 2.4. Examples .................................................................................... 1387 3. Zend_Test_PHPUnit_Db ......................................................................... 1389 3.1. Quickstart .................................................................................... 1389 3.2. Usage, API and Extensions Points ................................................ 1393 3.3. Using the Database Testing Adapter ............................................. 1395 Zend_Text .......................................................................................................... 1398 1. Zend_Text_Figlet .................................................................................... 1398 2. Zend_Text_Table ................................................................................... 1399 Zend_TimeSync ................................................................................................. 1401 1. Introduction ............................................................................................ 1401 1.1. Why Zend_TimeSync ? ................................................................ 1401 1.2. What is NTP ? ............................................................................. 1402 1.3. What is SNTP? ........................................................................... 1402 1.4. Problematic usage ....................................................................... 1402 1.5. Decide which server to use .......................................................... 1402 2. Working with Zend_TimeSync ................................................................. 1402 2.1. Generic Time Server Request ...................................................... 1403 2.2. Multiple Time Servers .................................................................. 1403 2.3. Protocols of Time Servers ............................................................ 1404 2.4. Using Ports for Time Servers ....................................................... 1404 2.5. Time Servers Options .................................................................. 1404 2.6. Using Different Time Servers ........................................................ 1405 2.7. Information from Time Servers ..................................................... 1405 2.8. Handling Exceptions .................................................................... 1405 Zend_Tool .......................................................................................................... 1407 1. Using Zend_Tool On The Command Line ................................................ 1407 1.1. Installation ................................................................................... 1407 1.2. General Purpose Commands ....................................................... 1408 1.3. Project Specific Commands .......................................................... 1408 1.4. Environment Customization .......................................................... 1411 2. Extending Zend_Tool .............................................................................. 1412 2.1. Overview of Zend_Tool ................................................................ 1412 2.2. Zend_Tool_Framework Extensions ............................................... 1413 2.3. Zend_Tool_Project Extensions ..................................................... 1421
    • Programmer's Reference Guide xxxi Zend_Tool_Framework ....................................................................................... 1423 1. Introduction ............................................................................................ 1423 2. Using the CLI Tool ................................................................................. 1423 2.1. Setting up the CLI tool ................................................................. 1424 2.2. Setting up the CLI tool on Unix-like Systems ................................. 1424 2.3. Setting up the CLI tool on Windows .............................................. 1426 2.4. Other Setup Considerations ......................................................... 1427 2.5. Where To Go Next? .................................................................... 1427 3. Architecture ............................................................................................ 1428 3.1. Registry ...................................................................................... 1428 3.2. Providers ..................................................................................... 1429 3.3. Loaders ....................................................................................... 1430 3.4. Manifests .................................................................................... 1431 3.5. Clients ........................................................................................ 1433 4. Creating Providers to use with Zend_Tool_Framework .............................. 1433 4.1. How Zend Tool finds your Providers ............................................. 1434 4.2. Basic Instructions for Creating Providers ....................................... 1434 4.3. The response object .................................................................... 1435 4.4. Advanced Development Information .............................................. 1435 5. Shipped System Providers ...................................................................... 1438 5.1. The Version Provider ................................................................... 1438 5.2. The Manifest Provider .................................................................. 1438 6. Extending and Configuring Zend_Tool_Framework ................................... 1438 6.1. Customizing Zend_Tool Console Client ......................................... 1438 Zend_Tool_Project ............................................................................................. 1441 1. Introduction ............................................................................................ 1441 2. Create A Project .................................................................................... 1441 3. Zend Tool Project Providers .................................................................... 1442 4. Zend_Tool_Project Internals .................................................................... 1442 4.1. Zend_Tool_Project Internal Xml Structure ...................................... 1442 4.2. Zend_Tool_Project Internal Extending ........................................... 1442 Zend_Translate .................................................................................................. 1443 1. Introduction ............................................................................................ 1443 1.1. Starting multi-lingual .................................................................... 1443 2. Adapters for Zend_Translate ................................................................... 1444 2.1. How to decide which translation adapter to use ............................. 1444 2.2. Integrate self written Adapters ...................................................... 1447 2.3. Speedup all Adapters .................................................................. 1447 3. Using Translation Adapters ..................................................................... 1447 3.1. Translation Source Structures ....................................................... 1449 4. Creating source files ............................................................................... 1451 4.1. Creating Array source files ........................................................... 1451 4.2. Creating Gettext source files ........................................................ 1451 4.3. Creating TMX source files ............................................................ 1452 4.4. Creating CSV source files ............................................................ 1453 4.5. Creating INI source files ............................................................... 1454 5. Additional features for translation ............................................................ 1454 5.1. Options for adapters .................................................................... 1454 5.2. Handling languages ..................................................................... 1457 5.3. Automatic source detection .......................................................... 1459 5.4. Checking for translations .............................................................. 1461 5.5. How to log not found translations .................................................. 1462 5.6. Accessing source data ................................................................. 1463 6. Plural notations for Translation ................................................................ 1464
    • Programmer's Reference Guide xxxii 6.1. Traditional plural translations ........................................................ 1464 6.2. Modern plural translations ............................................................ 1464 6.3. Plural source files ........................................................................ 1465 6.4. Custom plural rules ...................................................................... 1466 Zend_Uri ............................................................................................................ 1468 1. Zend_Uri ................................................................................................ 1468 1.1. Overview ..................................................................................... 1468 1.2. Creating a New URI .................................................................... 1468 1.3. Manipulating an Existing URI ........................................................ 1468 1.4. URI Validation ............................................................................. 1468 1.5. Common Instance Methods .......................................................... 1469 Zend_Validate .................................................................................................... 1471 1. Introduction ............................................................................................ 1471 1.1. What is a validator? ..................................................................... 1471 1.2. Basic usage of validators ............................................................. 1471 1.3. Customizing messages ................................................................ 1472 1.4. Using the static is() method .......................................................... 1473 1.5. Translating messages .................................................................. 1474 2. Standard Validation Classes ................................................................... 1475 2.1. Alnum ......................................................................................... 1475 2.2. Alpha .......................................................................................... 1475 2.3. Barcode ...................................................................................... 1475 2.4. Between ...................................................................................... 1479 2.5. Callback ...................................................................................... 1480 2.6. CreditCard ................................................................................... 1482 2.7. Ccnum ........................................................................................ 1486 2.8. Date ............................................................................................ 1486 2.9. Db_RecordExists and Db_NoRecordExists .................................... 1486 2.10. Digits ........................................................................................ 1488 2.11. EmailAddress ............................................................................ 1488 2.12. Float ......................................................................................... 1492 2.13. GreaterThan .............................................................................. 1492 2.14. Hex ........................................................................................... 1492 2.15. Hostname .................................................................................. 1492 2.16. Iban .......................................................................................... 1494 2.17. Identical .................................................................................... 1495 2.18. InArray ...................................................................................... 1496 2.19. Int ............................................................................................. 1498 2.20. Ip .............................................................................................. 1498 2.21. Isbn .......................................................................................... 1499 2.22. LessThan .................................................................................. 1501 2.23. NotEmpty .................................................................................. 1501 2.24. PostCode .................................................................................. 1502 2.25. Regex ....................................................................................... 1503 2.26. Sitemap Validators ..................................................................... 1503 2.27. StringLength .............................................................................. 1504 3. Validator Chains ..................................................................................... 1505 4. Writing Validators ................................................................................... 1505 5. Validation Messages ............................................................................... 1509 5.1. Using pre-translated validation messages ...................................... 1509 5.2. Limit the size of a validation message ........................................... 1510 Zend_Version ..................................................................................................... 1511 1. Getting the Zend Framework Version ...................................................... 1511 Zend_View ......................................................................................................... 1512
    • Programmer's Reference Guide xxxiii 1. Introduction ............................................................................................ 1512 1.1. Controller Script ........................................................................... 1512 1.2. View Script .................................................................................. 1512 1.3. Options ....................................................................................... 1513 1.4. Short Tags with View Scripts ........................................................ 1513 1.5. Utility Accessors .......................................................................... 1514 2. Controller Scripts .................................................................................... 1514 2.1. Assigning Variables ..................................................................... 1515 2.2. Rendering a View Script .............................................................. 1515 2.3. View Script Paths ........................................................................ 1516 3. View Scripts ........................................................................................... 1516 3.1. Escaping Output .......................................................................... 1517 3.2. Using Alternate Template Systems ............................................... 1518 4. View Helpers ......................................................................................... 1523 4.1. Initial Helpers .............................................................................. 1524 4.2. Helper Paths ............................................................................... 1574 4.3. Writing Custom Helpers ............................................................... 1575 4.4. Registering Concrete Helpers ....................................................... 1576 5. Zend_View_Abstract ............................................................................... 1576 Zend_Wildfire ..................................................................................................... 1578 1. Zend_Wildfire ......................................................................................... 1578 Zend_XmlRpc .................................................................................................... 1579 1. Introduction ............................................................................................ 1579 2. Zend_XmlRpc_Client .............................................................................. 1579 2.1. Introduction ................................................................................. 1579 2.2. Method Calls ............................................................................... 1579 2.3. Types and Conversions ............................................................... 1580 2.4. Server Proxy Object .................................................................... 1582 2.5. Error Handling ............................................................................. 1582 2.6. Server Introspection ..................................................................... 1583 2.7. From Request to Response .......................................................... 1584 2.8. HTTP Client and Testing .............................................................. 1584 3. Zend_XmlRpc_Server ............................................................................. 1584 3.1. Introduction ................................................................................. 1584 3.2. Basic Usage ................................................................................ 1584 3.3. Server Structure .......................................................................... 1585 3.4. Anatomy of a webservice ............................................................. 1585 3.5. Conventions ................................................................................ 1585 3.6. Utilizing Namespaces ................................................................... 1586 3.7. Custom Request Objects ............................................................. 1587 3.8. Custom Responses ..................................................................... 1587 3.9. Handling Exceptions via Faults ..................................................... 1587 3.10. Caching Server Definitions Between Requests ............................. 1588 3.11. Usage Examples ....................................................................... 1588 3.12. Performance optimization ........................................................... 1593 ZendX_Console_Process_Unix ........................................................................... 1595 1. ZendX_Console_Process_Unix ............................................................... 1595 1.1. Introduction ................................................................................. 1595 1.2. Basic usage of ZendX_Console_Process_Unix .............................. 1595 ZendX_JQuery ................................................................................................... 1597 1. Introduction ............................................................................................ 1597 2. ZendX_JQuery View Helpers .................................................................. 1597 2.1. jQuery() View Helper ................................................................... 1597 2.2. JQuery Helpers ........................................................................... 1603
    • Programmer's Reference Guide xxxiv 3. ZendX_JQuery Form Elements and Decorators ........................................ 1609 3.1. General Elements and Decorator Usage ....................................... 1609 3.2. Form Elements ............................................................................ 1610 3.3. Form Decorators ......................................................................... 1610 A. Zend Framework Requirements .............................................................................. 1613 A.1. Introduction ................................................................................................. 1613 A.1.1. PHP Version .................................................................................... 1613 A.1.2. PHP Extensions ............................................................................... 1613 A.1.3. Zend Framework Components .......................................................... 1617 A.1.4. Zend Framework Dependencies ........................................................ 1621 B. Zend Framework Migration Notes ........................................................................... 1642 B.1. Zend Framework 1.10 ................................................................................. 1642 B.1.1. Zend_Controller_Front ...................................................................... 1643 B.1.2. Zend_Feed_Reader .......................................................................... 1643 B.1.3. Zend_File_Transfer ........................................................................... 1644 B.1.4. Zend_Filter_HtmlEntities ................................................................... 1645 B.1.5. Zend_Filter_StripTags ....................................................................... 1645 B.1.6. Zend_Translate ................................................................................ 1645 B.1.7. Zend_Validate .................................................................................. 1645 B.2. Zend Framework 1.9 ................................................................................... 1646 B.2.1. Zend_File_Transfer ........................................................................... 1646 B.2.2. Zend_Filter ....................................................................................... 1647 B.2.3. Zend_Http_Client .............................................................................. 1647 B.2.4. Zend_Locale .................................................................................... 1648 B.2.5. Zend_View_Helper_Navigation .......................................................... 1649 B.2.6. Security fixes as with 1.9.7 ............................................................... 1650 B.3. Zend Framework 1.8 ................................................................................... 1651 B.3.1. Zend_Controller ................................................................................ 1651 B.3.2. Zend_Locale .................................................................................... 1651 B.4. Zend Framework 1.7 ................................................................................... 1651 B.4.1. Zend_Controller ................................................................................ 1652 B.4.2. Zend_File_Transfer ........................................................................... 1652 B.4.3. Zend_Locale .................................................................................... 1655 B.4.4. Zend_Translate ................................................................................ 1657 B.4.5. Zend_View ....................................................................................... 1658 B.5. Zend Framework 1.6 ................................................................................... 1658 B.5.1. Zend_Controller ................................................................................ 1658 B.5.2. Zend_File_Transfer ........................................................................... 1659 B.6. Zend Framework 1.5 ................................................................................... 1659 B.6.1. Zend_Controller ................................................................................ 1659 B.7. Zend Framework 1.0 ................................................................................... 1660 B.7.1. Zend_Controller ................................................................................ 1660 B.7.2. Zend_Currency ................................................................................. 1662 B.8. Zend Framework 0.9 ................................................................................... 1663 B.8.1. Zend_Controller ................................................................................ 1663 B.9. Zend Framework 0.8 ................................................................................... 1663 B.9.1. Zend_Controller ................................................................................ 1663 B.10. Zend Framework 0.6 ................................................................................. 1664 B.10.1. Zend_Controller .............................................................................. 1664 C. Zend Framework Coding Standard for PHP ............................................................. 1667 C.1. Overview .................................................................................................... 1667 C.1.1. Scope .............................................................................................. 1667 C.1.2. Goals ............................................................................................... 1668 C.2. PHP File Formatting .................................................................................... 1668
    • Programmer's Reference Guide xxxv C.2.1. General ........................................................................................... 1668 C.2.2. Indentation ....................................................................................... 1668 C.2.3. Maximum Line Length ...................................................................... 1668 C.2.4. Line Termination .............................................................................. 1668 C.3. Naming Conventions ................................................................................... 1668 C.3.1. Classes ........................................................................................... 1668 C.3.2. Abstract Classes .............................................................................. 1669 C.3.3. Interfaces ......................................................................................... 1669 C.3.4. Filenames ........................................................................................ 1669 C.3.5. Functions and Methods .................................................................... 1670 C.3.6. Variables ......................................................................................... 1670 C.3.7. Constants ........................................................................................ 1671 C.4. Coding Style ............................................................................................... 1671 C.4.1. PHP Code Demarcation .................................................................... 1671 C.4.2. Strings ............................................................................................. 1671 C.4.3. Arrays .............................................................................................. 1672 C.4.4. Classes ........................................................................................... 1673 C.4.5. Functions and Methods .................................................................... 1674 C.4.6. Control Statements ........................................................................... 1676 C.4.7. Inline Documentation ........................................................................ 1678 D. Zend Framework Documentation Standard .............................................................. 1681 D.1. Overview .................................................................................................... 1681 D.1.1. Scope .............................................................................................. 1681 D.2. Documentation File Formatting .................................................................... 1681 D.2.1. XML Tags ........................................................................................ 1681 D.2.2. Maximum Line Length ...................................................................... 1682 D.2.3. Indentation ....................................................................................... 1682 D.2.4. Line Termination .............................................................................. 1682 D.2.5. Empty tags ...................................................................................... 1682 D.2.6. Usage of whitespace within documents .............................................. 1683 D.2.7. Program Listings .............................................................................. 1685 D.2.8. Notes on specific inline tags ............................................................. 1686 D.2.9. Notes on specific block tags ............................................................. 1687 D.3. Recommendations ...................................................................................... 1688 D.3.1. Use editors without autoformatting ..................................................... 1688 D.3.2. Use Images ..................................................................................... 1688 D.3.3. Use Case Examples ......................................................................... 1688 D.3.4. Avoid Replicating phpdoc Contents ................................................... 1688 D.3.5. Use Links ........................................................................................ 1688 E. Recommended Project Structure for Zend Framework MVC Applications ................... 1690 E.1. Overview .................................................................................................... 1690 E.2. Recommended Project Directory Structure .................................................... 1690 E.3. Module Structure ......................................................................................... 1692 E.4. Rewrite Configuration Guide ........................................................................ 1693 E.4.1. Apache HTTP Server ........................................................................ 1693 E.4.2. Microsoft Internet Information Server ................................................. 1693 F. Zend Framework Performance Guide ...................................................................... 1695 F.1. Introduction ................................................................................................. 1695 F.2. Class Loading ............................................................................................. 1695 F.2.1. How can I optimize my include_path? ................................................ 1695 F.2.2. How can I eliminate unnecessary require_once statements? ................ 1697 F.2.3. How can I speed up plugin loading? .................................................. 1698 F.3. Zend_Db Performance ................................................................................. 1699
    • Programmer's Reference Guide xxxvi F.3.1. How can I reduce overhead introduced by Zend_Db_Table for retrieving table metadata? ......................................................................................... 1699 F.3.2. SQL generated with Zend_Db_Select s not hitting my indexes; how can I make it better? ......................................................................................... 1699 F.4. Internationalization (i18n) and Localization (l10n) ........................................... 1700 F.4.1. Which translation adapter should I use? ............................................. 1700 F.4.2. How can I make translation and localization even faster? ..................... 1700 F.5. View Rendering ........................................................................................... 1701 F.5.1. How can I speed up resolution of view helpers? .................................. 1701 F.5.2. How can I speed up view partials? .................................................... 1702 F.5.3. How can I speed up calls to the action() view helper? .......................... 1703 G. Copyright Information ............................................................................................. 1706
    • Part I. Introduction to Zend Framework
    • 2 Table of Contents Overview ......................................................................................................................... 3 Installation ....................................................................................................................... 4
    • 3 Overview Zend Framework is an open source framework for developing web applications and services with PHP 5. Zend Framework is implemented using 100% object-oriented code. The component structure of Zend Framework is somewhat unique; each component is designed with few dependencies on other components. This loosely coupled architecture allows developers to use components individually. We often call this a "use-at-will" design. While they can be used separately, Zend Framework components in the standard library form a powerful and extensible web application framework when combined. Zend Framework offers a robust, high performance MVC implementation, a database abstraction that is simple to use, and a forms component that implements HTML form rendering, validation, and filtering so that developers can consolidate all of these operations using one easy-to-use, object oriented interface. Other components, such as Zend_Auth and Zend_Acl, provide user authentication and authorization against all common credential stores. Still others implement client libraries to simply access to the most popular web services available. Whatever your application needs are, you're likely to find a Zend Framework component that can be used to dramatically reduce development time with a thoroughly tested foundation. The principal sponsor of the project 'Zend Framework' is Zend Technologies, but many companies have contributed components or significant features to the framework. Companies such as Google, Microsoft, and StrikeIron have partnered with Zend to provide interfaces to web services and other technologies that they wish to make available to Zend Framework developers. Zend Framework could not deliver and support all of these features without the help of the vibrant Zend Framework community. Community members, including contributors, make themselves available on mailing lists, IRC channels, and other forums. Whatever question you have about Zend Framework, the community is always available to address it.
    • 4 Installation See the requirements appendix for a detailed list of requirements for Zend Framework. Installing Zend Framework is extremely simple. Once you have downloaded and extracted the framework, you should add the /library folder in the distribution to the beginning of your include path. You may also want to move the library folder to another – possibly shared – location on your file system. • Download the latest stable release. This version, available in both .zip and .tar.gz formats, is a good choice for those who are new to Zend Framework. • Download the latest nightly snapshot. For those who would brave the cutting edge, the nightly snapshots represent the latest progress of Zend Framework development. Snapshots are bundled with documentation either in English only or in all available languages. If you anticipate working with the latest Zend Framework developments, consider using a Subversion (SVN) client. • Using a Subversion (SVN) client. Zend Framework is open source software, and the Subversion repository used for its development is publicly available. Consider using SVN to get Zend Framework if you already use SVN for your application development, want to contribute back to the framework, or need to upgrade your framework version more often than releases occur. Exporting is useful if you want to get a particular framework revision without the .svn directories as created in a working copy. Check out a working copy if you want contribute to Zend Framework, a working copy can be updated any time with svn update and changes can be commited to our SVN repository with the svn commit command. An externals definition is quite convenient for developers already using SVN to manage their application's working copies. The URL for the trunk of Zend Framework's SVN repository is: http://framework.zend.com/ svn/framework/standard/trunk Once you have a copy of Zend Framework available, your application needs to be able to access the framework classes. Though there are several ways to achieve this, your PHP include_path needs to contain the path to Zend Framework's library. Zend provides a QuickStart to get you up and running as quickly as possible. This is an excellent way to begin learning about the framework with an emphasis on real world examples that you can build upon. Since Zend Framework components are loosely coupled, you may use a somewhat unique combination of them in your own applications. The following chapters provide a comprehensive reference to Zend Framework on a component-by-component basis.
    • Part II. Learning Zend Framework
    • 6 Table of Contents Zend Framework Quick Start ............................................................................................ 8 1. Zend Framework & MVC Introduction ................................................................... 8 1.1. Zend Framework ....................................................................................... 8 1.2. Model-View-Controller ............................................................................... 8 2. Create Your Project ........................................................................................... 10 2.1. Install Zend Framework ........................................................................... 10 2.2. Create Your Project ................................................................................. 10 2.3. The Bootstrap ......................................................................................... 11 2.4. Configuration ........................................................................................... 12 2.5. Action Controllers .................................................................................... 12 2.6. Views ..................................................................................................... 13 2.7. Checkpoint .............................................................................................. 15 3. Create A Layout ................................................................................................ 15 4. Create a Model and Database Table ................................................................... 18 5. Create A Form ................................................................................................... 28 6. Congratulations! ................................................................................................. 31 Autoloading in Zend Framework ..................................................................................... 33 1. Introduction ........................................................................................................ 33 2. Goals and Design .............................................................................................. 33 2.1. Class Naming Conventions ...................................................................... 33 2.2. Autoloader Conventions and Design ......................................................... 33 3. Basic Autoloader Usage ..................................................................................... 34 4. Resource Autoloading ........................................................................................ 36 5. Conclusion ......................................................................................................... 37 Plugins in Zend Framework ............................................................................................ 38 1. Introduction ........................................................................................................ 38 2. Using Plugins .................................................................................................... 38 3. Conclusion ......................................................................................................... 40 Getting Started with Zend_Layout ................................................................................... 42 1. Introduction ........................................................................................................ 42 2. Using Zend_Layout ............................................................................................ 42 2.1. Layout Configuration ............................................................................... 42 2.2. Create a Layout Script ............................................................................ 43 2.3. Accessing the Layout Object .................................................................... 43 2.4. Other Operations ..................................................................................... 44 3. Zend_Layout: Conclusions .................................................................................. 45 Getting Started Zend_View Placeholders ........................................................................ 46 1. Introduction ........................................................................................................ 46 2. Basic Placeholder Usage ................................................................................... 46 3. Standard Placeholders ....................................................................................... 49 3.1. Setting the DocType ................................................................................ 49 3.2. Specifying the Page Title ......................................................................... 50 3.3. Specifying Stylesheets with HeadLink ....................................................... 51 3.4. Aggregating Scripts Using HeadScript ...................................................... 52 4. View Placeholders: Conclusion ........................................................................... 54 Understanding and Using Zend Form Decorators ............................................................ 55 1. Introduction ........................................................................................................ 55 2. Decorator Basics ............................................................................................... 55 2.1. Overview of the Decorator Pattern ........................................................... 55 2.2. Creating Your First Decorator .................................................................. 57 3. Layering Decorators ........................................................................................... 58
    • Learning Zend Framework 7 4. Rendering Individual Decorators ......................................................................... 62 5. Creating and Rendering Composite Elements ...................................................... 66 5.1. The Element ........................................................................................... 66 5.2. The Decorator ......................................................................................... 68 5.3. Conclusion .............................................................................................. 70 6. Conclusion ......................................................................................................... 70 Getting Started with Zend_Session, Zend_Auth, and Zend_Acl ......................................... 72 1. Building Multi-User Applications With Zend Framework ......................................... 72 1.1. Zend Framework ..................................................................................... 72 2. Managing User Sessions In ZF ........................................................................... 72 2.1. Introduction to Sessions .......................................................................... 72 2.2. Basic Usage of Zend_Session ................................................................. 73 2.3. Advanced Usage of Zend_Session ........................................................... 74 3. Authenticating Users in Zend Framework ............................................................ 74 3.1. Introduction to Authentication ................................................................... 74 3.2. Basic Usage of Zend_Auth ...................................................................... 74 4. Building an Authorization System in Zend Framework .......................................... 76 4.1. Introduction to Authorization ..................................................................... 76 4.2. Basic Usage of Zend_Acl ........................................................................ 77 Getting Started with Zend_Search_Lucene ...................................................................... 80 1. Zend_Search_Lucene Introduction ...................................................................... 80 2. Lucene Index Structure ...................................................................................... 81 3. Index Opening and Creation ............................................................................... 82 4. Indexing ............................................................................................................ 82 4.1. Indexing Policy ........................................................................................ 82 5. Searching .......................................................................................................... 83 6. Supported queries .............................................................................................. 84 7. Search result pagination ..................................................................................... 86 Getting Started with Zend_Paginator ............................................................................... 88 1. Introduction ........................................................................................................ 88 2. Simple Examples ............................................................................................... 88 3. Pagination Control and ScrollingStyles ................................................................ 90 4. Putting it all Together ......................................................................................... 91
    • 8 Zend Framework Quick Start 1. Zend Framework & MVC Introduction 1.1. Zend Framework Zend Framework is an open source, object oriented web application framework for PHP 5. Zend Framework is often called a 'component library', because it has many loosely coupled components that you can use more or less independently. But Zend Framework also provides an advanced Model-View-Controller (MVC) implementation that can be used to establish a basic structure for your Zend Framework applications. A full list of Zend Framework components along with short descriptions may be found in the components overview. This QuickStart will introduce you to some of Zend Framework's most commonly used components, including Zend_Controller, Zend_Layout, Zend_Config, Zend_Db, Zend_Db_Table, Zend_Registry, along with a few view helpers. Using these components, we will build a simple database-driven guest book application within minutes. The complete source code for this application is available in the following archives: • zip • tar.gz 1.2. Model-View-Controller So what exactly is this MVC pattern everyone keeps talking about, and why should you care? MVC is much more than just a three-letter acronym (TLA) that you can whip out anytime you want to sound smart; it has become something of a standard in the design of modern web applications. And for good reason. Most web application code falls under one of the following three categories: presentation, business logic, and data access. The MVC pattern models this separation of concerns well. The end result is that your presentation code can be consolidated in one part of your application with your business logic in another and your data access code in yet another. Many developers have found this well-defined separation indispensable for keeping their code organized, especially when more than one developer is working on the same application. More Information Let's break down the pattern and take a look at the individual pieces:
    • Zend Framework Quick Start 9 • Model - This is the part of your application that defines its basic functionality behind a set of abstractions. Data access routines and some business logic can be defined in the model. • View - Views define exactly what is presented to the user. Usually controllers pass data to each view to render in some format. Views will often collect data from the user, as well. This is where you're likely to find HTML markup in your MVC applications. • Controller - Controllers bind the whole pattern together. They manipulate models, decide which view to display based on the user's request and other factors, pass along the data that each view will need, or hand off control to another controller entirely. Most MVC experts recommend keeping controllers as skinny as possible.
    • Zend Framework Quick Start 10 Of course there is more to be said about this critical pattern, but this should give you enough background to understand the guestbook application we'll be building. 2. Create Your Project In order to create your project, you must first download and extract Zend Framework. 2.1. Install Zend Framework The easiest way to get Zend Framework along with a complete PHP stack is by installing Zend Server. Zend Server has native installers for Mac OSX, Windows, Fedora Core, and Ubuntu, as well as a universal installation package compatible with most Linux distributions. After you have installed Zend Server, the Framework files may be found under /usr/local/ zend/share/ZendFramework on Mac OSX and Linux, and C:Program FilesZend ZendServershareZendFramework on Windows. The include_path will already be configured to include Zend Framework. Alternately, you can Download the latest version of Zend Framework and extract the contents; make a note of where you have done so. Optionally, you can add the path to the library/ subdirectory of the archive to your php.ini's include_path setting. That's it! Zend Framework is now installed and ready to use. 2.2. Create Your Project zf Command Line Tool In your Zend Framework installation is a bin/ subdirectory, containing the scripts zf.sh and zf.bat for Unix-based and Windows-based users, respectively. Make a note of the absolute path to this script. Wherever you see references to zf.sh or zf.bat, please substitute the absolute path to the script. On Unix-like systems, you may want to use your shell's alias functionality: alias zf.sh=path/to/ZendFramework/bin/zf.sh. If you have problems setting up the zf command-line tool, please refer to the manual. Open a terminal (in Windows, Start -> Run, and then use cmd). Navigate to a directory where you would like to start a project. Then, use the path to the appropriate script, and execute one of the following: # Unix: % zf.sh create project quickstart # DOS/Windows: C:> zf.bat create project quickstart Running this command will create your basic site structure, including your initial controllers and views. The tree looks like the following:
    • Zend Framework Quick Start 11 quickstart |-- application | |-- Bootstrap.php | |-- configs | | `-- application.ini | |-- controllers | | |-- ErrorController.php | | `-- IndexController.php | |-- models | `-- views | |-- helpers | `-- scripts | |-- error | | `-- error.phtml | `-- index | `-- index.phtml |-- library |-- public | `-- index.php `-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml At this point, if you haven't added Zend Framework to your include_path, we recommend either copying or symlinking it into your library/ directory. In either case, you'll want to either recursively copy or symlink the library/Zend/ directory of your Zend Framework installation into the library/ directory of your project. On unix-like systems, that would look like one of the following: # Symlink: % cd library; ln -s path/to/ZendFramework/library/Zend . # Copy: % cd library; cp -r path/to/ZendFramework/library/Zend . On Windows systems, it may be easiest to do this from the Explorer. Now that the project is created, the main artifacts to begin understanding are the bootstrap, configuration, action controllers, and views. 2.3. The Bootstrap Your Bootstrap class defines what resources and components to initialize. By default, Zend Framework's Front Controller is initialized, and it uses the application/controllers/ as the default directory in which to look for action controllers (more on that later). The class looks like the following: // application/Bootstrap.php class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { } As you can see, not much is necessary to begin with.
    • Zend Framework Quick Start 12 2.4. Configuration While Zend Framework is itself configurationless, you often need to configure your application. The default configuration is placed in application/configs/application.ini, and contains some basic directives for setting your PHP environment (for instance, turning error reporting on and off), indicating the path to your bootstrap class (as well as its class name), and the path to your action controllers. It looks as follows: ; application/configs/application.ini [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 Several things about this file should be noted. First, when using INI-style configuration, you can reference constants directly and expand them; APPLICATION_PATH is actually a constant. Additionally note that there are several sections defined: production, staging, testing, and development. The latter three inherit settings from the "production" environment. This is a useful way to organize configuration to ensure that appropriate settings are available in each stage of application development. 2.5. Action Controllers Your application's action controllers contain your application workflow, and do the work of mapping your requests to the appropriate models and views. An action controller should have one or more methods ending in "Action"; these methods may then be requested via the web. By default, Zend Framework URLs follow the schema /controller/action, where "controller" maps to the action controller name (minus the "Controller" suffix) and "action" maps to an action method (minus the "Action" suffix). Typically, you always need an IndexController, which is a fallback controller and which also serves the home page of the site, and an ErrorController, which is used to indicate things such as HTTP 404 errors (controller or action not found) and HTTP 500 errors (application errors). The default IndexController is as follows: // application/controllers/IndexController.php class IndexController extends Zend_Controller_Action { public function init()
    • Zend Framework Quick Start 13 { /* Initialize action controller here */ } public function indexAction() { // action body } } And the default ErrorController is as follows: // application/controllers/ErrorController.php class ErrorController extends Zend_Controller_Action { public function errorAction() { $errors = $this->_getParam('error_handler'); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found $this->getResponse()->setHttpResponseCode(404); $this->view->message = 'Page not found'; break; default: // application error $this->getResponse()->setHttpResponseCode(500); $this->view->message = 'Application error'; break; } $this->view->exception = $errors->exception; $this->view->request = $errors->request; } } You'll note that (1) the IndexController contains no real code, and (2) the ErrorController makes reference to a "view" property. That leads nicely into our next subject. 2.6. Views Views in Zend Framework are written in plain old PHP. View scripts are placed in application/ views/scripts/, where they are further categorized using the controller names. In our case, we have an IndexController and an ErrorController, and thus we have corresponding index/ and error/ subdirectories within our view scripts directory. Within these subdirectories, you will then find and create view scripts that correspond to each controller action exposed; in the default case, we thus have the view scripts index/index.phtml and error/error.phtml. View scripts may contain any markup you want, and use the <?php opening tag and ?> closing tag to insert PHP directives. The following is what we install by default for the index/index.phtml view script:
    • Zend Framework Quick Start 14 <!-- application/views/scripts/index/index.phtml --> <style> a:link, a:visited { color: #0398CA; } span#zf-name { color: #91BE3F; } div#welcome { color: #FFFFFF; background-image: url(http://framework.zend.com/images/bkg_header.jpg); width: 600px; height: 400px; border: 2px solid #444444; overflow: hidden; text-align: center; } div#more-information { background-image: url(http://framework.zend.com/images/bkg_body-bottom.gif); height: 100%; } </style> <div id="welcome"> <h1>Welcome to the <span id="zf-name">Zend Framework!</span><h1 /> <h3>This is your project's main page<h3 /> <div id="more-information"> <p> <img src="http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png" /> </p> <p> Helpful Links: <br /> <a href="http://framework.zend.com/">Zend Framework Website</a> | <a href="http://framework.zend.com/manual/en/">Zend Framework Manual</a> </p> </div> </div> The error/error.phtml view script is slightly