1742
Programmer's Reference Guide Zend Framework 1.10.x

Zend Framework 1-10-x En

Embed Size (px)

Citation preview

Programmer's Reference Guide

Zend Framework 1.10.x

Programmer's Reference Guide: Zend Framework 1.10.xPublication date 01/27/2010 by mikaelkael (SVN 20684) Copyright 2005-2010 Zend Technologies Inc. (http://www.zend.com)

Table of ContentsI. 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

iii

Programmer's Reference Guide

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

iv

Programmer's Reference Guide

2. Zend_Amf_Server .................................................................................... 2.1. Connecting to the Server from Flex ................................................ 2.2. Error Handling ............................................................................... 2.3. AMF Responses ............................................................................ 2.4. Typed Objects ............................................................................... 2.5. Resources ..................................................................................... 2.6. Connecting to the Server from Flash ............................................... 2.7. Authentication ............................................................................... Zend_Application .................................................................................................. 1. Introduction .............................................................................................. 2. Zend_Application Quick Start .................................................................... 2.1. Using Zend_Tool ........................................................................... 2.2. Adding Zend_Application to your application .................................... 2.3. Adding and creating resources ....................................................... 2.4. Next steps with Zend_Application ................................................... 3. Theory of Operation ................................................................................. 3.1. Bootstrapping ................................................................................ 3.2. Resource Plugins .......................................................................... 4. Examples ................................................................................................. 5. Core Functionality .................................................................................... 5.1. Zend_Application ........................................................................... 5.2. Zend_Application_Bootstrap_Bootstrapper ...................................... 5.3. Zend_Application_Bootstrap_ResourceBootstrapper ........................ 5.4. Zend_Application_Bootstrap_BootstrapAbstract ............................... 5.5. Zend_Application_Bootstrap_Bootstrap ........................................... 5.6. Zend_Application_Resource_Resource ........................................... 5.7. Zend_Application_Resource_ResourceAbstract ............................... 6. Available Resource Plugins ...................................................................... 6.1. Zend_Application_Resource_Cachemanager ................................... 6.2. Zend_Application_Resource_Db ..................................................... 6.3. Zend_Application_Resource_Frontcontroller .................................... 6.4. Zend_Application_Resource_Layout ............................................... 6.5. Zend_Application_Resource_Locale ............................................... 6.6. Zend_Application_Resource_Log .................................................... 6.7. Zend_Application_Resource_Mail ................................................... 6.8. Zend_Application_Resource_Modules ............................................. 6.9. Zend_Application_Resource_Multidb ............................................... 6.10. Zend_Application_Resource_Navigation ........................................ 6.11. Zend_Application_Resource_Router ............................................. 6.12. Zend_Application_Resource_Session ............................................ 6.13. Zend_Application_Resource_View ................................................ Zend_Auth ........................................................................................................... 1. Introduction .............................................................................................. 1.1. Adapters ....................................................................................... 1.2. Results ......................................................................................... 1.3. Identity Persistence ....................................................................... 1.4. Usage ........................................................................................... 2. Database Table Authentication .................................................................. 2.1. Introduction ................................................................................... 2.2. Advanced Usage: Persisting a DbTable Result Object ...................... 2.3. Advanced Usage By Example ........................................................ 3. Digest Authentication ................................................................................ 3.1. Introduction ................................................................................... 3.2. Specifics .......................................................................................

132 134 136 136 136 138 138 140 142 142 142 142 144 145 147 147 148 152 153 156 156 159 160 161 164 165 166 168 168 168 169 170 170 171 172 172 174 175 175 176 176 178 178 178 179 180 183 184 184 186 186 188 188 188

v

Programmer's Reference Guide

3.3. Identity .......................................................................................... 4. HTTP Authentication Adapter .................................................................... 4.1. Introduction ................................................................................... 4.2. Design Overview ........................................................................... 4.3. Configuration Options .................................................................... 4.4. Resolvers ...................................................................................... 4.5. Basic Usage ................................................................................. 5. LDAP Authentication ................................................................................ 5.1. Introduction ................................................................................... 5.2. Usage ........................................................................................... 5.3. The API ........................................................................................ 5.4. Server Options .............................................................................. 5.5. Collecting Debugging Messages ..................................................... 5.6. Common Options for Specific Servers ............................................. 6. Open ID Authentication ............................................................................ 6.1. Introduction ................................................................................... 6.2. Specifics ....................................................................................... Zend_Barcode ..................................................................................................... 1. Introduction .............................................................................................. 2. Barcode creation using Zend_Barcode class .............................................. 2.1. Using Zend_Barcode::factory ......................................................... 2.2. Drawing a barcode ........................................................................ 2.3. Renderering a barcode .................................................................. 3. Zend_Barcode Objects ............................................................................. 3.1. Common Options .......................................................................... 3.2. Common Additional Getters ........................................................... 3.3. Description of shipped barcodes ..................................................... 4. Zend_Barcode Renderers ......................................................................... 4.1. Common Options .......................................................................... 4.2. Zend_Barcode_Renderer_Image .................................................... 4.3. Zend_Barcode_Renderer_Pdf ........................................................ Zend_Cache ........................................................................................................ 1. Introduction .............................................................................................. 2. The Theory of Caching ............................................................................. 2.1. The Zend_Cache Factory Method ................................................... 2.2. Tagging Records ........................................................................... 2.3. Cleaning the Cache ....................................................................... 3. Zend_Cache Frontends ............................................................................ 3.1. Zend_Cache_Core ......................................................................... 3.2. Zend_Cache_Frontend_Output ....................................................... 3.3. Zend_Cache_Frontend_Function .................................................... 3.4. Zend_Cache_Frontend_Class ........................................................ 3.5. Zend_Cache_Frontend_File ........................................................... 3.6. Zend_Cache_Frontend_Page ......................................................... 4. Zend_Cache Backends ............................................................................. 4.1. Zend_Cache_Backend_File ............................................................ 4.2. Zend_Cache_Backend_Sqlite ......................................................... 4.3. Zend_Cache_Backend_Memcached ............................................... 4.4. Zend_Cache_Backend_Apc ........................................................... 4.5. Zend_Cache_Backend_Xcache ...................................................... 4.6. Zend_Cache_Backend_ZendPlatform ............................................. 4.7. Zend_Cache_Backend_TwoLevels ................................................. 4.8. Zend_Cache_Backend_ZendServer_Disk and Zend_Cache_Backend_ZendServer_ShMem .........................................

188 189 189 189 189 190 191 192 192 192 193 195 198 199 200 200 201 203 203 203 203 204 204 205 206 208 208 215 215 216 217 218 218 220 221 221 222 222 222 226 226 227 229 229 234 234 235 236 237 237 237 238 239

vi

Programmer's Reference Guide

5. The Cache Manager ................................................................................ Zend_Captcha ..................................................................................................... 1. Introduction .............................................................................................. 2. Captcha Operation ................................................................................... 3. CAPTCHA Adapters ................................................................................. 3.1. Zend_Captcha_Word ..................................................................... 3.2. Zend_Captcha_Dumb .................................................................... 3.3. Zend_Captcha_Figlet ..................................................................... 3.4. Zend_Captcha_Image .................................................................... 3.5. Zend_Captcha_ReCaptcha ............................................................ Zend_CodeGenerator ........................................................................................... 1. Introduction .............................................................................................. 1.1. Theory of Operation ...................................................................... 2. Zend_CodeGenerator Examples ............................................................... 3. Zend_CodeGenerator Reference ............................................................... 3.1. Abstract Classes and Interfaces ..................................................... 3.2. Concrete CodeGenerator Classes .................................................. Zend_Config ........................................................................................................ 1. Introduction .............................................................................................. 2. Theory of Operation ................................................................................. 3. Zend_Config_Ini ....................................................................................... 4. Zend_Config_Xml ..................................................................................... Zend_Config_Writer .............................................................................................. 1. Zend_Config_Writer .................................................................................. Zend_Console_Getopt .......................................................................................... 1. Introduction .............................................................................................. 2. Declaring Getopt Rules ............................................................................ 2.1. Declaring Options with the Short Syntax ......................................... 2.2. Declaring Options with the Long Syntax .......................................... 3. Fetching Options and Arguments .............................................................. 3.1. Handling Getopt Exceptions ........................................................... 3.2. Fetching Options by Name ............................................................. 3.3. Reporting Options ......................................................................... 3.4. Fetching Non-option Arguments ..................................................... 4. Configuring Zend_Console_Getopt ............................................................ 4.1. Adding Option Rules ...................................................................... 4.2. Adding Help Messages .................................................................. 4.3. Adding Option Aliases ................................................................... 4.4. Adding Argument Lists ................................................................... 4.5. Adding Configuration ..................................................................... Zend_Controller ................................................................................................... 1. Zend_Controller Quick Start ...................................................................... 1.1. Introduction ................................................................................... 1.2. Quick Start .................................................................................... 2. Zend_Controller Basics ............................................................................. 3. The Front Controller ................................................................................. 3.1. Overview ....................................................................................... 3.2. Primary Methods ........................................................................... 3.3. Environmental Accessor Methods ................................................... 3.4. Front Controller Parameters ........................................................... 3.5. Extending the Front Controller ........................................................ 4. The Request Object ................................................................................. 4.1. Introduction ................................................................................... 4.2. HTTP Requests .............................................................................

239 243 243 243 244 244 245 245 245 246 247 247 247 249 253 253 255 261 261 262 263 265 270 270 273 273 274 274 274 275 275 276 276 277 277 277 277 278 278 279 281 281 281 281 284 287 287 288 289 291 291 292 292 292

vii

Programmer's Reference Guide

4.3. Subclassing the Request Object ..................................................... 5. The Standard Router ................................................................................ 5.1. Introduction ................................................................................... 5.2. Using a Router .............................................................................. 5.3. Basic Rewrite Router Operation ..................................................... 5.4. Default Routes .............................................................................. 5.5. Base URL and Subdirectories ........................................................ 5.6. Global Parameters ......................................................................... 5.7. Route Types ................................................................................. 5.8. Using Zend_Config with the RewriteRouter ..................................... 5.9. Subclassing the Router .................................................................. 6. The Dispatcher ........................................................................................ 6.1. Overview ....................................................................................... 6.2. Subclassing the Dispatcher ............................................................ 7. Action Controllers ..................................................................................... 7.1. Introduction ................................................................................... 7.2. Object Initialization ........................................................................ 7.3. Pre- and Post-Dispatch Hooks ....................................................... 7.4. Accessors ..................................................................................... 7.5. View Integration ............................................................................ 7.6. Utility Methods .............................................................................. 7.7. Subclassing the Action Controller ................................................... 8. Action Helpers ......................................................................................... 8.1. Introduction ................................................................................... 8.2. Helper Initialization ........................................................................ 8.3. The Helper Broker ......................................................................... 8.4. Built-in Action Helpers ................................................................... 8.5. Writing Your Own Helpers .............................................................. 9. The Response Object ............................................................................... 9.1. Usage ........................................................................................... 9.2. Manipulating Headers .................................................................... 9.3. Named Segments .......................................................................... 9.4. Testing for Exceptions in the Response Object ................................ 9.5. Subclassing the Response Object .................................................. 10. Plugins .................................................................................................. 10.1. Introduction ................................................................................. 10.2. Writing Plugins ............................................................................ 10.3. Using Plugins .............................................................................. 10.4. Retrieving and Manipulating Plugins ............................................. 10.5. Plugins Included in the Standard Distribution ................................. 11. Using a Conventional Modular Directory Structure .................................... 11.1. Introduction ................................................................................. 11.2. Specifying Module Controller Directories ....................................... 11.3. Routing to Modules ...................................................................... 11.4. Module or Global Default Controller .............................................. 12. MVC Exceptions ..................................................................................... 12.1. Introduction ................................................................................. 12.2. Handling Exceptions .................................................................... 12.3. MVC Exceptions You May Encounter ............................................ Zend_Currency .................................................................................................... 1. Introduction to Zend_Currency .................................................................. 1.1. Why should you use Zend_Currency? ............................................. 2. Using Zend_Currency ............................................................................... 2.1. Generic usage ...............................................................................

295 297 297 298 298 300 301 301 301 314 315 315 315 317 320 320 321 321 322 323 324 325 327 327 327 328 329 357 357 357 359 360 361 362 362 362 362 363 364 364 369 369 370 371 371 371 371 372 373 376 376 376 376 376

viii

Programmer's Reference Guide

2.2. Currency creation based on a locale ............................................... Options for currencies .............................................................................. What makes a currency? .......................................................................... Where is the currency? ............................................................................ How does the currency look like? .............................................................. How much is my currency? ...................................................................... 7.1. Working with currency values ......................................................... 7.2. Using precision on currencies ........................................................ 8. Calculating with currencies ....................................................................... 9. Exchanging currencies ............................................................................. 10. Additional informations on Zend_Currency ............................................... 10.1. Currency informations .................................................................. 10.2. Currency Performance Optimization .............................................. Zend_Date ........................................................................................................... 1. Introduction .............................................................................................. 1.1. Always Set a Default Timezone ...................................................... 1.2. Why Use Zend_Date? ................................................................... 2. Theory of Operation ................................................................................. 2.1. Internals ........................................................................................ 3. Basic Methods ......................................................................................... 3.1. Current Date ................................................................................. 3.2. Zend_Date by Example ................................................................. 4. Zend_Date API Overview ......................................................................... 4.1. Zend_Date Options ....................................................................... 4.2. Working with Date Values .............................................................. 4.3. Basic Zend_Date Operations Common to Many Date Parts .............. 4.4. Comparing Dates .......................................................................... 4.5. Getting Dates and Date Parts ........................................................ 4.6. Working with Fractions of Seconds ................................................. 4.7. Sunrise / Sunset ............................................................................ 5. Creation of Dates ..................................................................................... 5.1. Create the Actual Date .................................................................. 5.2. Create a Date from Database ........................................................ 5.3. Create Dates from an Array ........................................................... 6. Constants for General Date Functions ....................................................... 6.1. Using Constants ............................................................................ 6.2. List of All Constants ...................................................................... 6.3. Self-Defined OUTPUT Formats with ISO ......................................... 6.4. Self-Defined OUTPUT Formats Using PHP's date() Format Specifiers ............................................................................................. 7. Working Examples ................................................................................... 7.1. Checking Dates ............................................................................. 7.2. Sunrise and Sunset ....................................................................... 7.3. Time Zones ................................................................................... Zend_Db .............................................................................................................. 1. Zend_Db_Adapter .................................................................................... 1.1. Connecting to a Database Using an Adapter ................................... 1.2. Example Database ........................................................................ 1.3. Reading Query Results .................................................................. 1.4. Writing Changes to the Database ................................................... 1.5. Quoting Values and Identifiers ........................................................ 1.6. Controlling Database Transactions ................................................. 1.7. Listing and Describing Tables ........................................................ 1.8. Closing a Connection .................................................................... 3. 4. 5. 6. 7.

377 377 378 380 381 382 383 383 384 385 386 386 387 388 388 388 388 389 389 390 390 390 392 392 393 394 397 399 400 400 401 401 401 402 402 402 403 407 410 413 413 414 416 419 419 419 424 425 428 432 434 435 436

ix

Programmer's Reference Guide

2.

3.

4.

5.

6.

7.

8.

9.

1.9. Running Other Database Statements .............................................. 1.10. Retrieving Server Version ............................................................. 1.11. Notes on Specific Adapters .......................................................... Zend_Db_Statement ................................................................................. 2.1. Creating a Statement ..................................................................... 2.2. Executing a Statement ................................................................... 2.3. Fetching Results from a SELECT Statement ................................... Zend_Db_Profiler ..................................................................................... 3.1. Introduction ................................................................................... 3.2. Using the Profiler .......................................................................... 3.3. Advanced Profiler Usage ............................................................... 3.4. Specialized Profilers ...................................................................... Zend_Db_Select ....................................................................................... 4.1. Introduction ................................................................................... 4.2. Creating a Select Object ................................................................ 4.3. Building Select queries .................................................................. 4.4. Executing Select Queries ............................................................... 4.5. Other methods .............................................................................. Zend_Db_Table ....................................................................................... 5.1. Introduction ................................................................................... 5.2. Using Zend_Db_Table as a concrete class ...................................... 5.3. Defining a Table Class .................................................................. 5.4. Creating an Instance of a Table ..................................................... 5.5. Inserting Rows to a Table .............................................................. 5.6. Updating Rows in a Table .............................................................. 5.7. Deleting Rows from a Table ........................................................... 5.8. Finding Rows by Primary Key ........................................................ 5.9. Querying for a Set of Rows ............................................................ 5.10. Querying for a Single Row ........................................................... 5.11. Retrieving Table Metadata Information .......................................... 5.12. Caching Table Metadata .............................................................. 5.13. Customizing and Extending a Table Class ..................................... Zend_Db_Table_Row ............................................................................... 6.1. Introduction ................................................................................... 6.2. Fetching a Row ............................................................................. 6.3. Writing rows to the database .......................................................... 6.4. Serializing and unserializing rows ................................................... 6.5. Extending the Row class ............................................................... Zend_Db_Table_Rowset ........................................................................... 7.1. Introduction ................................................................................... 7.2. Fetching a Rowset ........................................................................ 7.3. Retrieving Rows from a Rowset ..................................................... 7.4. Retrieving a Rowset as an Array .................................................... 7.5. Serializing and Unserializing a Rowset ............................................ 7.6. Extending the Rowset class ........................................................... Zend_Db_Table Relationships ................................................................... 8.1. Introduction ................................................................................... 8.2. Defining Relationships ................................................................... 8.3. Fetching a Dependent Rowset ....................................................... 8.4. Fetching a Parent Row .................................................................. 8.5. Fetching a Rowset via a Many-to-many Relationship ........................ 8.6. Cascading Write Operations ........................................................... Zend_Db_Table_Definition ........................................................................ 9.1. Introduction ...................................................................................

437 438 438 441 441 442 442 444 444 446 447 448 449 449 450 450 463 464 466 466 466 466 469 471 473 473 474 475 479 479 480 482 485 485 485 487 489 490 493 493 493 493 495 496 497 498 498 498 500 502 503 505 507 507

x

Programmer's Reference Guide

9.2. Basic Usage ................................................................................. 9.3. Advanced Usage ........................................................................... Zend_Debug ........................................................................................................ 1. Dumping Variables ................................................................................... Zend_Dojo ........................................................................................................... 1. Introduction .............................................................................................. 2. Zend_Dojo_Data: dojo.data Envelopes ...................................................... 2.1. Zend_Dojo_Data Usage ................................................................. 2.2. Adding metadata to your containers ................................................ 2.3. Advanced Use Cases .................................................................... 3. Dojo View Helpers ................................................................................... 3.1. dojo() View Helper ......................................................................... 3.2. Dijit-Specific View Helpers ............................................................. 4. Dojo Form Elements and Decorators ......................................................... 4.1. Dijit-Specific Form Decorators ........................................................ 4.2. Dijit-Specific Form Elements ........................................................... 4.3. Dojo Form Examples ..................................................................... 5. Zend_Dojo build layer support .................................................................. 5.1. Introduction ................................................................................... 5.2. Generating Custom Module Layers with Zend_Dojo_BuildLayer ........ 5.3. Generating Build Profiles with Zend_Dojo_BuildLayer ...................... Zend_Dom ........................................................................................................... 1. Introduction .............................................................................................. 2. Zend_Dom_Query .................................................................................... 2.1. Theory of Operation ...................................................................... 2.2. Methods Available ......................................................................... Zend_Exception ................................................................................................... 1. Using Exceptions ..................................................................................... 2. Basic usage ............................................................................................. 3. Previous Exceptions ................................................................................. Zend_Feed .......................................................................................................... 1. Introduction .............................................................................................. 2. Importing Feeds ....................................................................................... 2.1. Custom feeds ................................................................................ 3. Retrieving Feeds from Web Pages ............................................................ 4. Consuming an RSS Feed ......................................................................... 5. Consuming an Atom Feed ........................................................................ 6. Consuming a Single Atom Entry ............................................................... 7. Modifying Feed and Entry structures ......................................................... 8. Custom Feed and Entry Classes ............................................................... 9. Zend_Feed_Reader .................................................................................. 9.1. Introduction ................................................................................... 9.2. Importing Feeds ............................................................................ 9.3. Retrieving Underlying Feed and Entry Sources ................................ 9.4. Cache Support and Intelligent Requests ......................................... 9.5. Locating Feed URIs from Websites ................................................. 9.6. Attribute Collections ....................................................................... 9.7. Retrieving Feed Information ........................................................... 9.8. Retrieving Entry/Item Information .................................................... 9.9. Extending Feed and Entry APIs ...................................................... 10. Zend_Feed_Writer .................................................................................. 10.1. Introduction ................................................................................. 10.2. Architecture ................................................................................. 10.3. Getting Started ............................................................................

507 509 511 511 512 512 512 512 514 514 516 516 521 534 535 537 554 555 555 556 558 561 561 561 561 562 564 564 564 564 566 566 567 567 571 572 573 574 575 575 577 577 577 578 579 580 581 582 585 588 592 592 592 593

xi

Programmer's Reference Guide

10.4. Setting Feed Data Points ............................................................. 10.5. Setting Entry Data Points ............................................................. 11. Zend_Feed_Pubsubhubbub .................................................................... 11.1. What is Pubsubhubbub? .............................................................. 11.2. Architecture ................................................................................. 11.3. Zend_Feed_Pubsubhubbub_Publisher .......................................... 11.4. Zend_Feed_Pubsubhubbub_Subscriber ........................................ Zend_File ............................................................................................................ 1. Zend_File_Transfer .................................................................................. 1.1. Supported Adapters for Zend_File_Transfer .................................... 1.2. Options for Zend_File_Transfer ...................................................... 1.3. Checking Files .............................................................................. 1.4. Additional File Informations ............................................................ 1.5. Progress for file uploads ................................................................ 2. Validators for Zend_File_Transfer .............................................................. 2.1. Using Validators with Zend_File_Transfer ........................................ 2.2. Count Validator ............................................................................. 2.3. Crc32 Validator ............................................................................. 2.4. ExcludeExtension Validator ............................................................ 2.5. ExcludeMimeType Validator ........................................................... 2.6. Exists Validator ............................................................................. 2.7. Extension Validator ........................................................................ 2.8. FilesSize Validator ......................................................................... 2.9. ImageSize Validator ....................................................................... 2.10. IsCompressed Validator ............................................................... 2.11. IsImage Validator ......................................................................... 2.12. Hash Validator ............................................................................. 2.13. Md5 Validator .............................................................................. 2.14. MimeType Validator ..................................................................... 2.15. NotExists Validator ...................................................................... 2.16. Sha1 Validator ............................................................................. 2.17. Size Validator .............................................................................. 2.18. WordCount Validator .................................................................... 3. Filters for Zend_File_Transfer ................................................................... 3.1. Using filters with Zend_File_Transfer .............................................. 3.2. Decrypt filter .................................................................................. 3.3. Encrypt filter .................................................................................. 3.4. LowerCase filter ............................................................................ 3.5. Rename filter ................................................................................ 3.6. UpperCase filter ............................................................................ Zend_Filter .......................................................................................................... 1. Introduction .............................................................................................. 1.1. What is a filter? ............................................................................. 1.2. Basic usage of filters ..................................................................... 1.3. Using the static staticFilter() method ............................................... 2. Standard Filter Classes ............................................................................ 2.1. Alnum ........................................................................................... 2.2. Alpha ............................................................................................ 2.3. BaseName .................................................................................... 2.4. Boolean ........................................................................................ 2.5. Callback ........................................................................................ 2.6. Compress and Decompress ........................................................... 2.7. Decrypt ......................................................................................... 2.8. Digits ............................................................................................

594 596 598 598 599 599 600 608 608 609 609 610 610 612 614 615 617 618 618 619 620 620 621 622 623 623 624 624 625 626 627 627 628 628 629 630 630 631 631 632 634 634 634 634 634 635 635 636 636 636 638 639 645 647

xii

Programmer's Reference Guide

2.9. Dir ................................................................................................ 2.10. Encrypt ....................................................................................... 2.11. HtmlEntities ................................................................................. 2.12. Int ............................................................................................... 2.13. LocalizedToNormalized ................................................................ 2.14. NormalizedToLocalized ................................................................ 2.15. Null ............................................................................................. 2.16. PregReplace ............................................................................... 2.17. RealPath ..................................................................................... 2.18. StringToLower ............................................................................. 2.19. StringToUpper ............................................................................. 2.20. StringTrim ................................................................................... 2.21. StripNewlines .............................................................................. 2.22. StripTags .................................................................................... 3. Filter Chains ............................................................................................ 3.1. Changing filter chain order ............................................................. 4. Writing Filters ........................................................................................... 5. Zend_Filter_Input ..................................................................................... 5.1. Declaring Filter and Validator Rules ................................................ 5.2. Creating the Filter and Validator Processor ..................................... 5.3. Retrieving Validated Fields and other Reports ................................. 5.4. Using Metacommands to Control Filter or Validator Rules ................. 5.5. Adding Filter Class Namespaces .................................................... 6. Zend_Filter_Inflector ................................................................................. 6.1. Operation ...................................................................................... 6.2. Setting Paths To Alternate Filters ................................................... 6.3. Setting the Inflector Target ............................................................. 6.4. Inflection Rules ............................................................................. 6.5. Utility Methods .............................................................................. 6.6. Using Zend_Config with Zend_Filter_Inflector .................................. Zend_Form .......................................................................................................... 1. Zend_Form .............................................................................................. 2. Zend_Form Quick Start ............................................................................ 2.1. Create a form object ...................................................................... 2.2. Add elements to the form ............................................................... 2.3. Render a form ............................................................................... 2.4. Check if a form is valid .................................................................. 2.5. Get error status ............................................................................. 2.6. Putting it together .......................................................................... 2.7. Using a Zend_Config Object .......................................................... 2.8. Conclusion .................................................................................... 3. Creating Form Elements Using Zend_Form_Element .................................. 3.1. Plugin Loaders .............................................................................. 3.2. Filters ........................................................................................... 3.3. Validators ...................................................................................... 3.4. Decorators .................................................................................... 3.5. Metadata and Attributes ................................................................. 3.6. Standard Elements ........................................................................ 3.7. Zend_Form_Element Methods ........................................................ 3.8. Configuration ................................................................................. 3.9. Custom Elements .......................................................................... 4. Creating Forms Using Zend_Form ............................................................ 4.1. Plugin Loaders .............................................................................. 4.2. Elements .......................................................................................

647 647 650 650 650 651 653 654 655 655 656 656 656 656 656 657 657 658 658 660 660 663 668 669 669 670 670 671 673 673 675 675 675 675 675 677 678 679 679 681 682 682 682 684 685 690 692 693 693 695 696 697 698 699

xiii

Programmer's Reference Guide

4.3. Display Groups ............................................................................. 4.4. Sub Forms .................................................................................... 4.5. Metadata and Attributes ................................................................. 4.6. Decorators .................................................................................... 4.7. Validation ...................................................................................... 4.8. Methods ........................................................................................ 4.9. Configuration ................................................................................. 4.10. Custom forms .............................................................................. 5. Creating Custom Form Markup Using Zend_Form_Decorator ...................... 5.1. Operation ...................................................................................... 5.2. Standard Decorators ...................................................................... 5.3. Custom Decorators ........................................................................ 5.4. Rendering Individual Decorators ..................................................... 6. Standard Form Elements Shipped With Zend Framework ............................ 6.1. Zend_Form_Element_Button .......................................................... 6.2. Zend_Form_Element_Captcha ....................................................... 6.3. Zend_Form_Element_Checkbox ..................................................... 6.4. Zend_Form_Element_File .............................................................. 6.5. Zend_Form_Element_Hidden ......................................................... 6.6. Zend_Form_Element_Hash ............................................................ 6.7. Zend_Form_Element_Image .......................................................... 6.8. Zend_Form_Element_MultiCheckbox .............................................. 6.9. Zend_Form_Element_Multiselect .................................................... 6.10. Zend_Form_Element_Password ................................................... 6.11. Zend_Form_Element_Radio ......................................................... 6.12. Zend_Form_Element_Reset ......................................................... 6.13. Zend_Form_Element_Select ......................................................... 6.14. Zend_Form_Element_Submit ........................................................ 6.15. Zend_Form_Element_Text ........................................................... 6.16. Zend_Form_Element_Textarea ..................................................... 7. Standard Form Decorators Shipped With Zend Framework ......................... 7.1. Zend_Form_Decorator_Callback ..................................................... 7.2. Zend_Form_Decorator_Captcha ..................................................... 7.3. Zend_Form_Decorator_Description ................................................. 7.4. Zend_Form_Decorator_DtDdWrapper ............................................. 7.5. Zend_Form_Decorator_Errors ........................................................ 7.6. Zend_Form_Decorator_Fieldset ...................................................... 7.7. Zend_Form_Decorator_File ............................................................ 7.8. Zend_Form_Decorator_Form .......................................................... 7.9. Zend_Form_Decorator_FormElements ............................................ 7.10. Zend_Form_Decorator_FormErrors ............................................... 7.11. Zend_Form_Decorator_HtmlTag ................................................... 7.12. Zend_Form_Decorator_Image ...................................................... 7.13. Zend_Form_Decorator_Label ....................................................... 7.14. Zend_Form_Decorator_PrepareElements ...................................... 7.15. Zend_Form_Decorator_ViewHelper ............................................... 7.16. Zend_Form_Decorator_ViewScript ................................................ 8. Internationalization of Zend_Form ............................................................. 8.1. Initializing I18n in Forms ................................................................ 8.2. Standard I18n Targets ................................................................... 9. Advanced Zend_Form Usage .................................................................... 9.1. Array Notation ............................................................................... 9.2. Multi-Page Forms .......................................................................... Zend_Gdata .........................................................................................................

703 707 708 709 711 713 716 717 719 719 720 720 723 723 723 723 724 725 728 728 728 728 729 730 730 730 731 731 731 732 732 732 732 732 733 733 733 733 733 733 734 734 734 735 735 735 736 737 737 738 739 739 741 743

xiv

Programmer's Reference Guide

1. Introduction .............................................................................................. 1.1. Structure of Zend_Gdata ................................................................ 1.2. Interacting with Google Services .................................................... 1.3. Obtaining instances of Zend_Gdata classes .................................... 1.4. Google Data Client Authentication .................................................. 1.5. Dependencies ............................................................................... 1.6. Creating a new Gdata client ........................................................... 1.7. Common Query Parameters ........................................................... 1.8. Fetching a Feed ............................................................................ 1.9. Working with Multi-page Feeds ...................................................... 1.10. Working with Data in Feeds and Entries ........................................ 1.11. Updating Entries .......................................................................... 1.12. Posting Entries to Google Servers ................................................ 1.13. Deleting Entries on Google Servers .............................................. 2. Authenticating with AuthSub ..................................................................... 2.1. Creating an AuthSub authenticated Http Client ................................ 2.2. Revoking AuthSub authentication ................................................... 3. Using the Book Search Data API .............................................................. 3.1. Authenticating to the Book Search service ...................................... 3.2. Searching for books ...................................................................... 3.3. Using community features .............................................................. 3.4. Book collections and My Library ..................................................... 4. Authenticating with ClientLogin .................................................................. 4.1. Creating a ClientLogin authenticated Http Client .............................. 4.2. Terminating a ClientLogin authenticated Http Client ......................... 5. Using Google Calendar ............................................................................ 5.1. Connecting To The Calendar Service ............................................. 5.2. Retrieving A Calendar List ............................................................. 5.3. Retrieving Events .......................................................................... 5.4. Creating Events ............................................................................. 5.5. Modifying Events ........................................................................... 5.6. Deleting Events ............................................................................. 5.7. Accessing Event Comments ........................................................... 6. Using Google Documents List Data API .................................................... 6.1. Get a List of Documents ................................................................ 6.2. Upload a Document ....................................................................... 6.3. Searching the documents feed ....................................................... 7. Using Google Health ................................................................................ 7.1. Connect To The Health Service ...................................................... 7.2. Profile Feed .................................................................................. 7.3. Profile List Feed ............................................................................ 7.4. Sending Notices to the Register Feed ............................................. 8. Using Google Spreadsheets ..................................................................... 8.1. Create a Spreadsheet .................................................................... 8.2. Get a List of Spreadsheets ............................................................ 8.3. Get a List of Worksheets ............................................................... 8.4. Interacting With List-based Feeds ................................................... 8.5. Interacting With Cell-based Feeds .................................................. 9. Using Google Apps Provisioning ............................................................... 9.1. Setting the current domain ............................................................. 9.2. Interacting with users ..................................................................... 9.3. Interacting with nicknames ............................................................. 9.4. Interacting with email lists .............................................................. 9.5. Interacting with email list recipients .................................................

743 743 744 744 745 745 745 746 747 747 748 748 749 749 750 750 751 751 752 752 753 755 757 757 758 758 758 761 761 763 766 767 767 768 768 768 769 770 770 773 774 775 776 776 776 776 776 779 780 780 781 784 786 787

xv

Programmer's Reference Guide

9.6. Handling errors ............................................................................. 10. Using Google Base ................................................................................ 10.1. Connect To The Base Service ...................................................... 10.2. Retrieve Items ............................................................................. 10.3. Insert, Update, and Delete Customer Items ................................... 11. Using Picasa Web Albums ...................................................................... 11.1. Connecting To The Service .......................................................... 11.2. Understanding and Constructing Queries ...................................... 11.3. Retrieving Feeds And Entries ....................................................... 11.4. Creating Entries ........................................................................... 11.5. Deleting Entries ........................................................................... 12. Using the YouTube Data API .................................................................. 12.1. Authentication .............................................................................. 12.2. Developer Keys and Client ID ...................................................... 12.3. Retrieving public video feeds ........................................................ 12.4. Retrieving video comments .......................................................... 12.5. Retrieving playlist feeds ............................................................... 12.6. Retrieving a list of a user's subscriptions ....................................... 12.7. Retrieving a user's profile ............................................................. 12.8. Uploading Videos to YouTube ...................................................... 12.9. Browser-based upload ................................................................. 12.10. Checking upload status .............................................................. 12.11. Other Functions ......................................................................... 13. Catching Gdata Exceptions ..................................................................... Zend_Http ............................................................................................................ 1. Introduction .............................................................................................. 1.1. Using Zend_Http_Client ................................................................. 1.2. Configuration Parameters ............................................................... 1.3. Performing Basic HTTP Requests .................................................. 1.4. Adding GET and POST parameters ............................................... 1.5. Accessing Last Request and Response .......................................... 2. Zend_Http_Client - Advanced Usage ......................................................... 2.1. HTTP Redirections ........................................................................ 2.2. Adding Cookies and Using Cookie Persistence ................................ 2.3. Setting Custom Request Headers ................................................... 2.4. File Uploads .................................................................................. 2.5. Sending Raw POST Data .............................................................. 2.6. HTTP Authentication ...................................................................... 2.7. Sending Multiple Requests With the Same Client ............................. 2.8. Data Streaming ............................................................................. 3. Zend_Http_Client - Connection Adapters ................................................... 3.1. Overview ....................................................................................... 3.2. The Socket Adapter ....................................................................... 3.3. The Proxy Adapter ........................................................................ 3.4. The cURL Adapter ........................................................................ 3.5. The Test Adapter .......................................................................... 3.6. Creating your own connection adapters .......................................... 4. Zend_Http_Cookie and Zend_Http_CookieJar ............................................ 4.1. Introduction ................................................................................... 4.2. Instantiating Zend_Http_Cookie Objects .......................................... 4.3. Zend_Http_Cookie getter methods .................................................. 4.4. Zend_Http_Cookie: Matching against a scenario .............................. 4.5. The Zend_Http_CookieJar Class: Instantiation ................................. 4.6. Adding Cookies to a Zend_Http_CookieJar object ............................

788 788 789 791 793 794 795 797 798 802 803 805 805 805 805 807 808 808 809 809 811 811 812 812 814 814 814 814 815 816 817 817 817 817 818 819 820 820 821 822 823 823 823 826 827 828 831 833 833 833 834 835 836 837

xvi

Programmer's Reference Guide

4.7. Retrieving Cookies From a Zend_Http_CookieJar object .................. 5. Zend_Http_Response ............................................................................... 5.1. Introduction ................................................................................... 5.2. Boolean Tester Methods ................................................................ 5.3. Accessor Methods ......................................................................... 5.4. Static HTTP Response Parsers ...................................................... Zend_InfoCard ..................................................................................................... 1. Introduction .............................................................................................. 1.1. Basic Theory of Usage .................................................................. 1.2. Using as part of Zend_Auth ........................................................... 1.3. Using the Zend_InfoCard component standalone ............................. 1.4. Working with a Claims object ......................................................... 1.5. Attaching Information Cards to existing accounts ............................. 1.6. Creating Zend_InfoCard Adapters ................................................... Zend_Json ........................................................................................................... 1. Introduction .............................................................................................. 2. Basic Usage ............................................................................................ 2.1. Pretty-printing JSON ...................................................................... 3. Advanced Usage of Zend_Json ................................................................ 3.1. JSON Objects ............................................................................... 3.2. Encoding PHP objects ................................................................... 3.3. Internal Encoder/Decoder ............................................................... 3.4. JSON Expressions ........................................................................ 4. XML to JSON conversion ......................................................................... 5. Zend_Json_Server - JSON-RPC server ..................................................... 5.1. Advanced Details .......................................................................... Zend_Layout ........................................................................................................ 1. Introduction .............................................................................................. 2. Zend_Layout Quick Start .......................................................................... 2.1. Layout scripts ................................................................................ 2.2. Using Zend_Layout with the Zend Framework MVC ......................... 2.3. Using Zend_Layout as a Standalone Component ............................. 2.4. Sample Layout .............................................................................. 3. Zend_Layout Configuration Options ........................................................... 3.1. Examples ...................................................................................... 4. Zend_Layout Advanced Usage ................................................................. 4.1. Custom View Objects .................................................................... 4.2. Custom Front Controller Plugins ..................................................... 4.3. Custom Action Helpers .................................................................. 4.4. Custom Layout Script Path Resolution: Using the Inflector ................ Zend_Ldap .......................................................................................................... 1. Introduction .............................................................................................. 1.1. Theory of operation ....................................................................... 2. API overview ........................................................................................... 2.1. Configuration / options ................................................................... 2.2. API Reference ............................................................................... 3. Usage Scenarios ...................................................................................... 3.1. Authentication scenarios ................................................................ 3.2. Basic CRUD operations ................................................................. 3.3. Extended operations ...................................................................... 4. Tools ....................................................................................................... 4.1. Creation and modification of DN strings .......................................... 4.2. Using the filter API to create search filters ....................................... 4.3. Modify LDAP entries using the Attribute API ....................................

837 838 838 839 839 840 842 842 842 842 844 844 845 846 848 848 848 848 848 848 849 849 849 850 851 854 860 860 860 860 861 862 863 865 865 867 867 867 868 868 870 870 870 873 873 875 900 900 901 902 903 903 903 903

xvii

Programmer's Reference Guide

5. Object oriented access to the LDAP tree using Zend_Ldap_Node ................ 5.1. Basic CRUD operations ................................................................. 5.2. Extended operations ...................................................................... 5.3. Tree traversal ................................................................................ 6. Getting information from the LDAP server .................................................. 6.1. RootDSE ....................................................................................... 6.2. Schema Browsing ......................................................................... 7. Serializing LDAP data to and from LDIF .................................................... 7.1. Serialize a LDAP entry to LDIF ...................................................... 7.2. Deserialize a LDIF string into a LDAP entry ..................................... Zend_Loader ....................................................................................................... 1. Loading Files and Classes Dynamically ..................................................... 1.1. Loading Files ................................................................................ 1.2. Loading Classes ............................................................................ 1.3. Testing if a File is Readable ........................................................... 1.4. Using the Autoloader ..................................................................... 2. The Autoloader ........................................................................................ 2.1. Using the Autoloader ..................................................................... 2.2. Selecting a Zend Framework version .............................................. 2.3. The Autoloader Interface ................................................................ 2.4. Autoloader Reference .................................................................... 3. Resource Autoloaders .............................................................................. 3.1. Resource autoloader usage ........................................................... 3.2. The Module Resource Autoloader ................................................... 3.3. Using Resource Autoloaders as Object Factories ............................. 3.4. Resource Autoloader Reference ..................................................... 4. Loading Plugins ....................................................................................... 4.1. Basic Use Case ............................................................................ 4.2. Manipulating Plugin Paths .............................................................. 4.3. Testing for Plugins and Retrieving Class Names .............................. 4.4. Getting Better Performance for Plugins ........................................... Zend_Locale ........................................................................................................ 1. Introduction .............................................................................................. 1.1. What is Localization ...................................................................... 1.2. What is a Locale? ......................................................................... 1.3. How are Locales Represented? ...................................................... 1.4. Selecting the Right Locale ............................................................. 1.5. Usage of automatic Locales ........................................................... 1.6. Using a default Locale ................................................................... 1.7. ZF Locale-Aware Classes .............................................................. 1.8. Application wide locale .................................................................. 1.9. Zend_Locale_Format::setOptions(array $options) ............................ 1.10. Speed up Zend_Locale and its subclasses .................................... 2. Using Zend_Locale .................................................................................. 2.1. Copying, Cloning, and Serializing Locale Objects ............................. 2.2. Equality ......................................................................................... 2.3. Default locales .............................................................................. 2.4. Set a new locale ........................................................................... 2.5. Getting the language and region .................................................... 2.6. Obtaining localized strings ............................................................. 2.7. Obtaining translations for "yes" and "no" ......................................... 2.8. Get a list of all known locales ........................................................ 2.9. Detecting locales ........................................................................... 3. Normalization and Localization ..................................................................

903 903 904 904 904 904 904 905 905 906 908 908 908 908 909 910 910 911 912 914 914 917 917 919 919 919 919 920 921 921 922 923 923 923 924 924 925 925 926 927 927 928 928 929 929 929 930 930 930 931 945 946 946 948

xviii

Programmer's Reference Guide

3.1. Number normalization: getNumber($input, Array $options) ................ 3.2. Number localization ....................................................................... 3.3. Number testing .............................................................................. 3.4. Float value normalization ............................................................... 3.5. Floating point value localization ...................................................... 3.6. Floating point value testing ............................................................ 3.7. Integer value normalization ............................................................ 3.8. Integer point value localization ....................................................... 3.9. Integer value testing ...................................................................... 3.10. Numeral System Conversion ........................................................ 4. Working with Dates and Times ................................................................. 4.1. Normalizing Dates and Times ........................................................ 4.2. Testing Dates ................................................................................ 4.3. Normalizing a Time ....................................................................... 4.4. Testing Times ............................................................................... 5. Supported locales .................................................................................... Zend_Log ............................................................................................................ 1. Overview ................................................................................................. 1.1. Creating a Log .............................................................................. 1.2. Logging Messages ........................................................................ 1.3. Destroying a Log ........................................................................... 1.4. Using Built-in Priorities ........................................