40
Programmer's Reference Guide Zend Framework

stacks on stacks on stacks

Embed Size (px)

DESCRIPTION

zend framework 1.6 documentation

Citation preview

Page 1: stacks on stacks on stacks

Programmer's Reference GuideZend Framework

Page 2: stacks on stacks on stacks

Programmer's Reference Guide: Zend FrameworkPublished 2008-08-30Copyright © 2005-2008 Zend Technologies Inc. (http://www.zend.com)

Page 3: stacks on stacks on stacks

Table of Contents1. Introduction to Zend Framework ......................................................................................... 1

Overview ................................................................................................................... 1Installation ................................................................................................................. 1

2. Zend_Acl ........................................................................................................................ 3Introduction ................................................................................................................ 3

About Resources ................................................................................................. 3About Roles ....................................................................................................... 3Creating the Access Control List (ACL) ................................................................... 5Registering Roles ................................................................................................ 5Defining Access Controls ...................................................................................... 6Querying the ACL ............................................................................................... 7

Refining Access Controls .............................................................................................. 7Precise Access Controls ........................................................................................ 7Removing Access Controls .................................................................................... 9

Advanced Usage ........................................................................................................ 10Storing ACL Data for Persistence .......................................................................... 10Writing Conditional ACL Rules with Assertions ...................................................... 11

3. Zend_Auth .................................................................................................................... 13Introduction .............................................................................................................. 13

Adapters .......................................................................................................... 13Results ............................................................................................................. 14Identity Persistence ............................................................................................ 15Using Zend_Auth ............................................................................................... 18

Database Table Authentication ...................................................................................... 20Introduction ...................................................................................................... 20Advanced Use: Persisting a DbTable Result Object ................................................... 22Advanced Usage By Example ............................................................................... 23

Digest Authentication ................................................................................................. 25Introduction ...................................................................................................... 25Specifics .......................................................................................................... 25Identity ............................................................................................................ 25

HTTP Authentication Adapter ...................................................................................... 26Introduction ...................................................................................................... 26Design Overview ............................................................................................... 26Configuration Options ........................................................................................ 27Resolvers ......................................................................................................... 27Basic Usage ...................................................................................................... 28

LDAP Authentication ................................................................................................. 29Introduction ...................................................................................................... 29Usage .............................................................................................................. 29The API ........................................................................................................... 31Server Options .................................................................................................. 33Collecting Debugging Messages ........................................................................... 35Common Options for Specific Servers ................................................................... 36

Open ID Authentication .............................................................................................. 37Introduction ...................................................................................................... 37Specifics .......................................................................................................... 38

4. Zend_Cache .................................................................................................................. 40Introduction .............................................................................................................. 40The theory of caching ................................................................................................. 43

The Zend_Cache factory method ....................................................................... 43

iii

Page 4: stacks on stacks on stacks

Tagging records ................................................................................................. 44Cleaning the cache ............................................................................................. 44

Zend_Cache frontends ................................................................................................ 45Zend_Cache_Core .............................................................................................. 45Zend_Cache_Frontend_Output ............................................................................. 48Zend_Cache_Frontend_Function .......................................................................... 48Zend_Cache_Frontend_Class ............................................................................... 49Zend_Cache_Frontend_File ................................................................................. 50Zend_Cache_Frontend_Page ................................................................................ 51

Zend_Cache backends ................................................................................................ 56Zend_Cache_Backend_File .................................................................................. 56Zend_Cache_Backend_Sqlite ............................................................................... 56Zend_Cache_Backend_Memcached ...................................................................... 57Zend_Cache_Backend_Apc ................................................................................. 57Zend_Cache_Backend_Xcache ............................................................................. 58Zend_Cache_Backend_ZendPlatform .................................................................... 58

5. Zend_Captcha ................................................................................................................ 59Introduction .............................................................................................................. 59Captcha Operation ..................................................................................................... 59Captcha Adapters ....................................................................................................... 60

Zend_Captcha_Word .......................................................................................... 60Zend_Captcha_Dumb ......................................................................................... 61Zend_Captcha_Figlet .......................................................................................... 61Zend_Captcha_Image ......................................................................................... 61Zend_Captcha_ReCaptcha ................................................................................... 62

6. Zend_Config ................................................................................................................. 63Introduction .............................................................................................................. 63Theory of Operation ................................................................................................... 64Zend_Config_Ini ....................................................................................................... 65Zend_Config_Xml ..................................................................................................... 67

7. Zend_Console_Getopt ..................................................................................................... 70Introduction to Getopt ................................................................................................. 70Declaring Getopt Rules ............................................................................................... 71

Declaring Options with the Short Syntax ................................................................ 71Declaring Options with the Long Syntax ................................................................ 71

Fetching Options and Arguments .................................................................................. 72Handling Getopt Exceptions ................................................................................. 72Fetching Options by Name .................................................................................. 73Reporting Options .............................................................................................. 74Fetching Non-option Arguments ........................................................................... 74

Configuring Zend_Console_Getopt ............................................................................... 74Adding Option Rules .......................................................................................... 74Adding Help Messages ....................................................................................... 75Adding Option Aliases ........................................................................................ 75Adding Argument Lists ....................................................................................... 76Adding Configuration ......................................................................................... 76

8. Zend_Controller ............................................................................................................. 78Zend_Controller Quick Start ........................................................................................ 78

Introduction ...................................................................................................... 78Quick Start ....................................................................................................... 78

Zend_Controller Basics ............................................................................................... 81The Front Controller ................................................................................................... 84

Overview ......................................................................................................... 84Primary Methods ............................................................................................... 84

iv

Programmer's Reference Guide

Page 5: stacks on stacks on stacks

Environmental Accessor Methods ......................................................................... 86Front Controller Parameters ................................................................................. 88Subclassing the Front Controller ........................................................................... 88

The Request Object .................................................................................................... 89Introduction ...................................................................................................... 89HTTP Requests ................................................................................................. 89Subclassing the Request Object ............................................................................ 92

The Standard Router ................................................................................................... 94Introduction ...................................................................................................... 94Using a router ................................................................................................... 95Basic Rewrite Router operation ............................................................................ 95Default routes .................................................................................................... 96Base URL and subdirectories ............................................................................... 98Route Types ...................................................................................................... 98Using Zend_Config with the RewriteRouter .......................................................... 106Subclassing the Router ...................................................................................... 107

The Dispatcher ........................................................................................................ 107Overview ........................................................................................................ 107Subclassing the Dispatcher ................................................................................. 108

Action Controllers .................................................................................................... 112Introduction .................................................................................................... 112Object initialization .......................................................................................... 113Pre- and Post-Dispatch Hooks ............................................................................. 114Accessors ....................................................................................................... 114View Integration .............................................................................................. 115Utility Methods ................................................................................................ 117Subclassing the Action Controller ........................................................................ 117

Action Helpers ......................................................................................................... 119Introduction .................................................................................................... 119Helper Initialization .......................................................................................... 120The Helper Broker ............................................................................................ 120Built-in Action Helpers ...................................................................................... 122Writing Your Own Helpers ................................................................................. 156

The Response Object ................................................................................................ 157Usage ............................................................................................................. 157Manipulating Headers ....................................................................................... 159Named Segments ............................................................................................. 159Testing for Exceptions in the Response Object ....................................................... 161Subclassing the Response Object ......................................................................... 162

Plugins ................................................................................................................... 162Introduction .................................................................................................... 162Writing Plugins ................................................................................................ 163Using Plugins .................................................................................................. 163Retrieving and Manipulating Plugins .................................................................... 164Plugins Included in the Standard Distribution ........................................................ 164

Using a Conventional Modular Directory Structure ......................................................... 169Introduction .................................................................................................... 169Specifying Module Controller Directories ............................................................. 170Routing to modules ........................................................................................... 172Module or Global Default Controller .................................................................... 172

MVC Exceptions ...................................................................................................... 172Introduction .................................................................................................... 172How can you handle exceptions? ......................................................................... 173MVC Exceptions You May Encounter .................................................................. 174

v

Programmer's Reference Guide

Page 6: stacks on stacks on stacks

Migrating from Previous Versions ................................................................................ 176Migrating from 1.5.x to 1.6.0 or newer ................................................................. 177Migrating from 1.0.x to 1.5.0 or newer ................................................................. 177Migrating from 0.9.3 to 1.0.0RC1 or newer ........................................................... 178Migrating from 0.9.2 to 0.9.3 or newer ................................................................. 180Migrating from 0.6.0 to 0.8.0 or newer ................................................................. 180Migrating from 0.2.0 or before to 0.6.0 ................................................................. 181

9. Zend_Currency ............................................................................................................. 185Introduction to Zend_Currency ................................................................................... 185

Why should Zend_Currency be used ? ............................................................. 185How to work with currencies ...................................................................................... 185

Create output from an currency ........................................................................... 187Changing the format of a currency ....................................................................... 188Informational methods for Zend_Currency ............................................................ 190Settings new default values ................................................................................ 191Speed up Zend_Currency ................................................................................... 191

Migrating from Previous Versions ................................................................................ 192Migrating from 1.0.2 to 1.0.3 or newer ................................................................. 192

10. Zend_Date ................................................................................................................. 194Introduction ............................................................................................................ 194

Always Set a Default Timezone ........................................................................... 194Why Use Zend_Date? ....................................................................................... 194

Theory of Operation ................................................................................................. 195Internals ......................................................................................................... 195

Basic Methods ......................................................................................................... 196The current date ............................................................................................... 196Zend_Date by Example ..................................................................................... 196

Zend_Date API Overview .......................................................................................... 198Zend_Date Options ........................................................................................... 198Working with Date Values .................................................................................. 200Basic Zend_Date Operations Common to Many Date Parts ................................... 201Comparing Dates ............................................................................................. 205Getting Dates and Date Parts .............................................................................. 206Working with Fractions of Seconds ...................................................................... 208Sunrise / Sunset ............................................................................................... 208

Creation of dates ...................................................................................................... 208Create the actual date ........................................................................................ 208Create a date from database ................................................................................ 209Create dates from an array ................................................................................. 210

Constants for General Date Functions .......................................................................... 210Using Constants ............................................................................................... 210List of All Constants ......................................................................................... 211Self-Defined OUTPUT Formats with ISO ............................................................. 216Self-defined OUTPUT formats using PHP's date() format specifiers ........................... 220

Working examples .................................................................................................... 223Checking dates ................................................................................................ 223Sunrise and Sunset ........................................................................................... 224Timezones ...................................................................................................... 226

11. Zend_Db ................................................................................................................... 229Zend_Db_Adapter .................................................................................................... 229

Connecting to a Database using an Adapter ........................................................... 229The example database ....................................................................................... 234Reading Query Results ...................................................................................... 236

vi

Programmer's Reference Guide

Page 7: stacks on stacks on stacks

Writing Changes to the Database ......................................................................... 239Quoting Values and Identifiers ............................................................................ 243Controlling Database Transactions ....................................................................... 246Listing and Describing Tables ............................................................................. 247Closing a Connection ........................................................................................ 248Running Other Database Statements .................................................................... 249Notes on Specific Adapters ................................................................................ 249

Zend_Db_Statement ................................................................................................. 252Creating a Statement ......................................................................................... 252Executing a Statement ....................................................................................... 253Fetching Results from a SELECT Statement .......................................................... 253

Zend_Db_Profiler .................................................................................................... 256Introduction .................................................................................................... 256Using the Profiler ............................................................................................. 258Advanced Profiler Usage ................................................................................... 259Specialized Profilers ......................................................................................... 261

Zend_Db_Select ...................................................................................................... 262Overview of the Select Object ............................................................................. 262Creating a Select Object .................................................................................... 262Building Select queries ...................................................................................... 263Executing Select Queries ................................................................................... 278Other methods ................................................................................................. 279

Zend_Db_Table ....................................................................................................... 281Introduction to Table Class ................................................................................. 281Defining a Table Class ....................................................................................... 281Creating an Instance of a Table ........................................................................... 285Inserting Rows to a Table ................................................................................... 286Updating Rows in a Table .................................................................................. 289Deleting Rows from a Table ............................................................................... 290Finding Rows by Primary Key ............................................................................ 290Querying for a Set of Rows ................................................................................ 292Querying for a Single Row ................................................................................. 296Retrieving Table Metadata Information ................................................................. 296Caching Table Metadata .................................................................................... 297Customizing and Extending a Table Class ............................................................. 299

Zend_Db_Table_Row ............................................................................................... 303Introduction .................................................................................................... 303Fetching a Row ................................................................................................ 303Writing rows to the database ............................................................................... 305Serializing and unserializing rows ....................................................................... 307Extending the Row class .................................................................................... 309

Zend_Db_Table_Rowset ............................................................................................ 313Introduction .................................................................................................... 313Fetching a Rowset ............................................................................................ 313Retrieving Rows from a Rowset .......................................................................... 314Retrieving a Rowset as an Array .......................................................................... 316Serializing and Unserializing a Rowset ................................................................. 317Extending the Rowset class ................................................................................ 318

Zend_Db_Table Relationships .................................................................................... 319Introduction .................................................................................................... 319Defining Relationships ...................................................................................... 319Fetching a Dependent Rowset ............................................................................. 322Fetching a Parent Row ....................................................................................... 324Fetching a Rowset via a Many-to-many Relationship .............................................. 325

vii

Programmer's Reference Guide

Page 8: stacks on stacks on stacks

Cascading Write Operations ............................................................................... 32812. Zend_Debug .............................................................................................................. 332

Dumping Variables ................................................................................................... 33213. Zend_Dojo ................................................................................................................. 333

Introduction ............................................................................................................ 333Zend_Dojo_Data: dojo.data Envelopes ......................................................................... 333

Zend_Dojo_Data Usage ..................................................................................... 333Advanced Use Cases ......................................................................................... 335

Dojo View Helpers ................................................................................................... 337dojo() View Helper ........................................................................................... 337Dijit-Specific View Helpers ................................................................................ 343

Dojo Form Elements and Decorators ............................................................................ 355Dijit-Specific Form Decorators ........................................................................... 356Dijit-Specific Form Elements ............................................................................. 358Dojo Form Examples ........................................................................................ 374

14. Zend_Dom ................................................................................................................. 382Introduction ............................................................................................................ 382Zend_Dom_Query .................................................................................................... 382

Theory of Operation ......................................................................................... 382Methods Available ............................................................................................ 383

15. Zend_Exception .......................................................................................................... 385Using Exceptions ..................................................................................................... 385

16. Zend_Feed ................................................................................................................. 386Introduction ............................................................................................................ 386Importing Feeds ....................................................................................................... 387

Custom feeds ................................................................................................... 388Retrieving Feeds from Web Pages ................................................................................ 391Consuming an RSS Feed ........................................................................................... 392Consuming an Atom Feed .......................................................................................... 393Consuming a Single Atom Entry ................................................................................. 394Modifying Feed and Entry structures ............................................................................ 395Custom Feed and Entry Classes .................................................................................. 396

17. Zend_File .................................................................................................................. 399Zend_File_Transfer .................................................................................................. 399Validators for Zend_File_Transfer ............................................................................... 400

Using validators with Zend_File_Transfer ................................................... 401Count validator ............................................................................................... 403Exists validator ................................................................................................ 403Extension validator .......................................................................................... 404FilesSize validator ............................................................................................ 405ImageSize validator .......................................................................................... 406MimeType validator ......................................................................................... 407NotExists validator ........................................................................................... 408Size validator .................................................................................................. 408

18. Zend_Filter ................................................................................................................ 410Introduction ............................................................................................................ 410

What is a filter? ............................................................................................... 410Basic usage of filters ......................................................................................... 410Using the static get() method .......................................................................... 410

Standard Filter Classes .............................................................................................. 411Alnum ............................................................................................................ 411Alpha ............................................................................................................. 411BaseName ...................................................................................................... 411

viii

Programmer's Reference Guide

Page 9: stacks on stacks on stacks

Digits ............................................................................................................. 411Dir ................................................................................................................ 411HtmlEntities .................................................................................................... 411Int ................................................................................................................. 411StripNewlines .................................................................................................. 412RealPath ......................................................................................................... 412StringToLower ................................................................................................. 412StringToUpper ................................................................................................. 412StringTrim ...................................................................................................... 412StripTags ........................................................................................................ 412

Filter Chains ............................................................................................................ 412Writing Filters ......................................................................................................... 413Zend_Filter_Input .................................................................................................... 413

Declaring Filter and Validator Rules ..................................................................... 414Creating the Filter and Validator Processor ............................................................ 416Retrieving Validated Fields and other Reports ........................................................ 416Using Metacommands to Control Filter or Validator Rules ....................................... 419Adding Filter Class Namespaces ......................................................................... 424

Zend_Filter_Inflector ................................................................................................ 425Operation ........................................................................................................ 426Setting Paths To Alternate Filters ......................................................................... 426Setting the Inflector Target ................................................................................. 427Inflection Rules ............................................................................................... 428Utility Methods ................................................................................................ 430Using Zend_Config with Zend_Filter_Inflector ...................................................... 431

19. Zend_Form ................................................................................................................ 432Zend_Form ............................................................................................................. 432Zend_Form Quick Start ............................................................................................. 432

Create a form object .......................................................................................... 432Add elements to the form ................................................................................... 433Render a form .................................................................................................. 435Check if a form is valid ..................................................................................... 437Get error status ................................................................................................ 437Putting it together ............................................................................................. 438Using a Zend_Config object ............................................................................... 440Conclusion ...................................................................................................... 440

Creating Form Elements Using Zend_Form_Element ...................................................... 441Plugin Loaders ................................................................................................. 441Filters ............................................................................................................ 443Validators ....................................................................................................... 444Decorators ...................................................................................................... 449Metadata and Attributes ..................................................................................... 452Standard Elements ............................................................................................ 453Zend_Form_Element Methods ............................................................................ 453Configuration .................................................................................................. 455Custom Elements ............................................................................................. 456

Creating Forms Using Zend_Form ............................................................................... 458Plugin Loaders ................................................................................................. 458Elements ........................................................................................................ 459Display Groups ................................................................................................ 465Sub Forms ...................................................................................................... 469Metadata and Attributes ..................................................................................... 470Decorators ...................................................................................................... 472Validation ....................................................................................................... 474

ix

Programmer's Reference Guide

Page 10: stacks on stacks on stacks

Methods ......................................................................................................... 476Configuration .................................................................................................. 479Custom forms .................................................................................................. 480

Creating Custom Form Markup Using Zend_Form_Decorator .......................................... 482Operation ........................................................................................................ 482Standard Decorators .......................................................................................... 483Custom Decorators ........................................................................................... 483

Standard Form Elements Shipped With Zend Framework ................................................. 486Zend_Form_Element_Button .............................................................................. 486Zend_Form_Element_Captcha ............................................................................ 487Zend_Form_Element_Checkbox ......................................................................... 488Zend_Form_Element_File .................................................................................. 488Zend_Form_Element_Hidden ............................................................................. 489Zend_Form_Element_Hash ................................................................................ 489Zend_Form_Element_Image .............................................................................. 490Zend_Form_Element_MultiCheckbox .................................................................. 490Zend_Form_Element_Multiselect ........................................................................ 491Zend_Form_Element_Password .......................................................................... 491Zend_Form_Element_Radio ............................................................................... 492Zend_Form_Element_Reset ............................................................................... 492Zend_Form_Element_Select ............................................................................... 492Zend_Form_Element_Submit ............................................................................. 493Zend_Form_Element_Text ................................................................................. 493Zend_Form_Element_Textarea ........................................................................... 493

Standard Form Decorators Shipped With Zend Framework ............................................... 493Zend_Form_Decorator_Callback ......................................................................... 493Zend_Form_Decorator_Captcha .......................................................................... 494Zend_Form_Decorator_Description ..................................................................... 494Zend_Form_Decorator_DtDdWrapper ................................................................. 494Zend_Form_Decorator_Errors ............................................................................ 495Zend_Form_Decorator_Fieldset .......................................................................... 495Zend_Form_Decorator_Form ............................................................................. 495Zend_Form_Decorator_FormElements ................................................................. 495Zend_Form_Decorator_HtmlTag ......................................................................... 495Zend_Form_Decorator_Image ............................................................................ 495Zend_Form_Decorator_Label ............................................................................. 496Zend_Form_Decorator_ViewHelper .................................................................... 496Zend_Form_Decorator_ViewScript ...................................................................... 496

Internationalization of Zend_Form ............................................................................... 498Initializing I18n in Forms ................................................................................... 498Standard I18n Targets ........................................................................................ 499

Advanced Zend_Form Usage ...................................................................................... 500Array Notation ................................................................................................. 500Multi-Page Forms ............................................................................................. 503

20. Zend_Gdata ............................................................................................................... 514Introduction to Gdata ................................................................................................ 514

Structure of Zend_Gdata .................................................................................... 514Interacting with Google Services ......................................................................... 515Obtaining instances of Zend_Gdata classes ........................................................... 515Google Data Client Authentication ...................................................................... 516Dependencies .................................................................................................. 516Creating a new Gdata client ................................................................................ 516Common query parameters ................................................................................. 517Fetching a feed ................................................................................................ 518

x

Programmer's Reference Guide

Page 11: stacks on stacks on stacks

Working with multi-page feeds ........................................................................... 518Working with data in feeds and entries ................................................................. 519Updating entries ............................................................................................... 519Posting entries to Google servers ......................................................................... 520Deleting entries on Google servers ....................................................................... 520

Authenticating with AuthSub ...................................................................................... 521Creating an AuthSub authenticated Http Client ....................................................... 521Revoking AuthSub authentication ........................................................................ 522

Authenticating with ClientLogin ................................................................................. 523Creating a ClientLogin authenticated Http Client .................................................... 523Terminating a ClientLogin authenticated Http Client ............................................... 524

Using Google Calendar ............................................................................................. 524Connecting To The Calendar Service .................................................................... 524Retrieving A Calendar List ................................................................................. 527Retrieving Events ............................................................................................. 528Creating Events ............................................................................................... 531Modifying Events ............................................................................................. 534Deleting Events ............................................................................................... 535Accessing Event Comments ............................................................................... 535

Using Google Documents List Data API ....................................................................... 536Get a List of Documents .................................................................................... 536Upload a Document .......................................................................................... 536Searching the documents feed ............................................................................. 537

Using Google Spreadsheets ........................................................................................ 538Create a Spreadsheet ......................................................................................... 538Get a List of Spreadsheets .................................................................................. 538Get a List of Worksheets .................................................................................... 539Interacting With List-based Feeds ........................................................................ 539Interacting With Cell-based Feeds ....................................................................... 542

Using Google Apps Provisioning ................................................................................. 543Setting the current domain ................................................................................. 543Interacting with users ........................................................................................ 544Interacting with nicknames ................................................................................. 548Interacting with email lists ................................................................................. 550Interacting with email list recipients ..................................................................... 552Handling errors ................................................................................................ 553

Using Google Base ................................................................................................... 553Connect To The Base Service ............................................................................. 554Retrieve Items ................................................................................................. 557Insert, Update, and Delete Customer Items ............................................................ 558

Using the YouTube Data API ...................................................................................... 561Authentication ................................................................................................. 561Developer Keys and Client ID ............................................................................. 561Retrieving public video feeds .............................................................................. 561Retrieving video comments ................................................................................ 564Retrieving playlist feeds .................................................................................... 564Retrieving a list of a user's subscriptions ............................................................... 565Retrieving a user's profile ................................................................................... 565Uploading Videos to YouTube ............................................................................. 565Browser-based upload ....................................................................................... 567Checking upload status ...................................................................................... 568Other Functions ............................................................................................... 569

Using Picasa Web Albums .......................................................................................... 569Connecting To The Service ................................................................................ 569

xi

Programmer's Reference Guide

Page 12: stacks on stacks on stacks

Understanding and Constructing Queries .............................................................. 572Retrieving Feeds And Entries .............................................................................. 573Creating Entries ............................................................................................... 577Deleting Entries ............................................................................................... 579

Catching Gdata Exceptions ........................................................................................ 58121. Zend_Http ................................................................................................................. 583

Zend_Http_Client - Introduction ................................................................................. 583Introduction .................................................................................................... 583Configuration Parameters ................................................................................... 583Performing Basic HTTP Requests ....................................................................... 584Adding GET and POST parameters ..................................................................... 585Accessing Last Request and Response .................................................................. 586

Zend_Http_Client - Advanced Usage ........................................................................... 586HTTP Redirections ........................................................................................... 586Adding Cookies and Using Cookie Persistence ...................................................... 587Setting Custom Request Headers ......................................................................... 588File Uploads .................................................................................................... 589Sending Raw POST Data ................................................................................... 590HTTP Authentication ........................................................................................ 590Sending Multiple Requests With the Same Client ................................................... 591

Zend_Http_Client - Connection Adapters ...................................................................... 592Overview ........................................................................................................ 592The Socket Adapter .......................................................................................... 593The Proxy Adapter ........................................................................................... 594The Test Adapter .............................................................................................. 595Creating your own connection adapters ................................................................. 597

Zend_Http_Cookie and Zend_Http_CookieJar ............................................................... 600Introduction .................................................................................................... 600Instantiating Zend_Http_Cookie Objects ............................................................... 600Zend_Http_Cookie getter methods ....................................................................... 602Zend_Http_Cookie: Matching against a scenario .................................................... 603The Zend_Http_CookieJar Class: Instantiation ....................................................... 605Adding Cookies to a Zend_Http_CookieJar object .................................................. 605Retrieving Cookies From a Zend_Http_CookieJar object ......................................... 605

Zend_Http_Response ................................................................................................ 606Introduction .................................................................................................... 606Boolean Tester Methods .................................................................................... 607Accessor Methods ............................................................................................ 608Static HTTP Response Parsers ............................................................................ 609

22. Zend_InfoCard ........................................................................................................... 611Introduction ............................................................................................................ 611

Basic Theory of Usage ...................................................................................... 611Using as part of Zend_Auth ................................................................................ 612Using the Zend_InfoCard component standalone .................................................... 613Working with a Claims object ............................................................................. 614Attaching Information Cards to existing accounts ................................................... 614Creating Zend_InfoCard adapters ........................................................................ 615

23. Zend_Json ................................................................................................................. 617Introduction ............................................................................................................ 617Basic Usage ............................................................................................................ 617JSON Objects .......................................................................................................... 617XML to JSON conversion .......................................................................................... 618Zend_Json_Server - JSON-RPC server ......................................................................... 620

Advanced Details ............................................................................................. 623

xii

Programmer's Reference Guide

Page 13: stacks on stacks on stacks

24. Zend_Layout .............................................................................................................. 629Introduction ............................................................................................................ 629Zend_Layout Quick Start ........................................................................................... 629

Layout scripts .................................................................................................. 629Using Zend_Layout with the Zend Framework MVC .............................................. 630Using Zend_Layout as a Standalone Component .................................................... 632Sample Layout ................................................................................................. 632

Zend_Layout Configuration Options ............................................................................ 633Examples ........................................................................................................ 633

Zend_Layout Advanced Usage .................................................................................... 635Custom View Objects ........................................................................................ 635Custom Front Controller Plugins ......................................................................... 636Custom Action Helpers ...................................................................................... 636Custom Layout Script Path Resolution: Using the Inflector ...................................... 637

25. Zend_Ldap ................................................................................................................ 639Introduction ............................................................................................................ 639

Theory of Operation ......................................................................................... 63926. Zend_Loader .............................................................................................................. 644

Loading Files and Classes Dynamically ........................................................................ 644Loading Files .................................................................................................. 644Loading Classes ............................................................................................... 644Testing if a File is Readable ................................................................................ 645Using the Autoloader ........................................................................................ 645

Loading Plugins ....................................................................................................... 646Basic Use Case ................................................................................................ 647Manipulating Plugin Paths ................................................................................. 648Testing for Plugins and Retrieving Class Names ..................................................... 649

27. Zend_Locale .............................................................................................................. 650Introduction ............................................................................................................ 650

What is Localization ......................................................................................... 650What is a Locale? ............................................................................................ 651How are Locales Represented? ............................................................................ 651Selecting the Right Locale ................................................................................. 652Usage of automatic Locales ................................................................................ 652Using a default Locale ....................................................................................... 653ZF Locale-Aware Classes ................................................................................... 654Application wide locale ..................................................................................... 655Zend_Locale_Format::setOptions(array $options) ................................................... 655Speed up Zend_Locale and its subclasses .............................................................. 656

Using Zend_Locale .................................................................................................. 656Copying, Cloning, and Serializing Locale Objects .................................................. 657Equality .......................................................................................................... 657Default locales ................................................................................................. 657Set a new locale ............................................................................................... 658Getting the language and region .......................................................................... 658Obtaining localized strings ................................................................................. 659Obtaining translations for "yes" and "no" .............................................................. 669Get a list of all known locales ............................................................................. 670

Normalization and Localization .................................................................................. 671Number normalization: getNumber($input, Array $options) ..................................... 671Number localization .......................................................................................... 672Number testing ................................................................................................ 674Float value normalization ................................................................................... 674Floating point value localization .......................................................................... 674

xiii

Programmer's Reference Guide

Page 14: stacks on stacks on stacks

Floating point value testing ................................................................................ 675Integer value normalization ................................................................................ 675Integer point value localization ........................................................................... 675Integer value testing .......................................................................................... 676Numeral System Conversion ............................................................................... 676

Working with Dates and Times ................................................................................... 678Normalizing Dates and Times ............................................................................. 678Testing Dates ................................................................................................... 682Normalizing a Time .......................................................................................... 683Testing Times .................................................................................................. 683

Supported locales ..................................................................................................... 68428. Zend_Log .................................................................................................................. 696

Overview ................................................................................................................ 696Creating a Log ................................................................................................. 696Logging Messages ............................................................................................ 696Destroying a Log .............................................................................................. 697Using Built-in Priorities ..................................................................................... 697Adding User-defined Priorities ............................................................................ 698Understanding Log Events ................................................................................. 698

Writers ................................................................................................................... 699Writing to Streams ........................................................................................... 699Writing to Databases ......................................................................................... 700Writing to Firebug ............................................................................................ 700Stubbing Out the Writer ..................................................................................... 703Testing with the Mock ....................................................................................... 703Compositing Writers ......................................................................................... 703

Formatters .............................................................................................................. 704Simple Formatting ............................................................................................ 704Formatting to XML .......................................................................................... 704

Filters .................................................................................................................... 705Filtering for All Writers ..................................................................................... 706Filtering for a Writer Instance ............................................................................. 706

29. Zend_Mail ................................................................................................................. 707Introduction ............................................................................................................ 707

Getting started ................................................................................................. 707Configuring the default sendmail transport ............................................................ 708

Sending via SMTP ................................................................................................... 708Sending Multiple Mails per SMTP Connection .............................................................. 709Using Different Transports ......................................................................................... 710HTML E-Mail ......................................................................................................... 711Attachments ............................................................................................................ 711Adding Recipients .................................................................................................... 712Controlling the MIME Boundary ................................................................................. 712Additional Headers ................................................................................................... 713Character Sets ......................................................................................................... 713Encoding ................................................................................................................ 713SMTP Authentication ................................................................................................ 713Securing SMTP Transport .......................................................................................... 714Reading Mail Messages ............................................................................................. 715

Simple example using Pop3 ................................................................................ 715Opening a local storage ..................................................................................... 715Opening a remote storage .................................................................................. 716Fetching messages and simple methods ................................................................ 717Working with messages ..................................................................................... 717

xiv

Programmer's Reference Guide

Page 15: stacks on stacks on stacks

Checking for flags ............................................................................................ 720Using folders ................................................................................................... 721Advanced Use ................................................................................................. 723

30. Zend_Measure ............................................................................................................ 727Introduction ............................................................................................................ 727Creation of Measurements ......................................................................................... 727

Creating measurements from integers and floats ..................................................... 728Creating measurements from strings .................................................................... 728Measurements from localized strings ................................................................... 729

Outputting measurements .......................................................................................... 730Automatic output ............................................................................................. 730Outputting values ............................................................................................. 730Output with unit of measurement ......................................................................... 731Output as localized string ................................................................................... 731

Manipulating Measurements ....................................................................................... 731Convert .......................................................................................................... 731Add and subtract .............................................................................................. 732Compare ......................................................................................................... 733Compare ......................................................................................................... 734Manually change values ..................................................................................... 734Manually change types ...................................................................................... 734

Types of measurements ............................................................................................. 735Hints for Zend_Measure_Binary ......................................................................... 737Hints for Zend_Measure_Number ....................................................................... 737Roman numbers ............................................................................................... 738

31. Zend_Memory ............................................................................................................ 739Overview ................................................................................................................ 739

Introduction .................................................................................................... 739Theory of Operation ......................................................................................... 739

Memory Manager ..................................................................................................... 741Creating a Memory Manager .............................................................................. 741Managing Memory Objects ................................................................................ 741Memory Manager Settings ................................................................................. 742

Memory Objects ...................................................................................................... 743Movable ......................................................................................................... 743Locked ........................................................................................................... 743Memory container 'value' property. ...................................................................... 744Memory container interface ................................................................................ 744

32. Zend_Mime ............................................................................................................... 747Zend_Mime ............................................................................................................ 747

Introduction .................................................................................................... 747Static Methods and Constants ............................................................................. 747Instantiating Zend_Mime ................................................................................... 747

Zend_Mime_Message ............................................................................................... 748Introduction .................................................................................................... 748Instantiation .................................................................................................... 748Adding MIME Parts ......................................................................................... 748Boundary handling ........................................................................................... 748parsing a string to create a Zend_Mime_Message object (experimental) ...................... 748

Zend_Mime_Part ..................................................................................................... 749Introduction .................................................................................................... 749Instantiation .................................................................................................... 749Methods for rendering the message part to a string .................................................. 749

33. Zend_OpenId ............................................................................................................. 750

xv

Programmer's Reference Guide

Page 16: stacks on stacks on stacks

Introduction ............................................................................................................ 750What is OpenID? .............................................................................................. 750How Does it Work? ........................................................................................... 750Zend_OpenId Structure ..................................................................................... 751Supported Standards ......................................................................................... 751

Zend_OpenId_Consumer Basics ................................................................................. 751OpenID Authentication ...................................................................................... 751Combine all Steps in One Page ........................................................................... 753Realm ............................................................................................................ 754Immediate Check ............................................................................................. 755Zend_OpenId_Consumer_Storage ....................................................................... 755Simple Registration Extension ............................................................................ 759Integration with Zend_Auth ............................................................................... 761Integration with Zend_Controller ........................................................................ 763

Zend_OpenId_Provider ............................................................................................. 763Quick Start ...................................................................................................... 763Combine all together ......................................................................................... 766Simple Registration Extension ............................................................................ 767What Else? ...................................................................................................... 769

34. Zend_Paginator ........................................................................................................... 770Introduction ............................................................................................................ 770Usage ..................................................................................................................... 770

Paginating data collections ................................................................................. 770Rendering pages with view scripts ....................................................................... 771

Configuration .......................................................................................................... 775Advanced usage ....................................................................................................... 776

Custom data source adapters ............................................................................... 776Custom scrolling styles ...................................................................................... 776

35. Zend_Pdf ................................................................................................................... 778Introduction. ............................................................................................................ 778Creating and loading PDF documents. .......................................................................... 778Save changes to the PDF document. ............................................................................. 779Document pages. ...................................................................................................... 780

Page creation. .................................................................................................. 780Page cloning. ................................................................................................... 781

Drawing ................................................................................................................. 782Geometry ........................................................................................................ 782Colors ............................................................................................................ 782Shape Drawing ................................................................................................ 782Text Drawing ................................................................................................... 785Using fonts ..................................................................................................... 786Starting in 1.5, Extracting fonts. .......................................................................... 789Image Drawing ................................................................................................ 791Line drawing style ............................................................................................ 792Fill style ......................................................................................................... 792Rotations ........................................................................................................ 793Save/restore graphics state ................................................................................. 793Clipping draw area ........................................................................................... 794Styles ............................................................................................................. 795Transparency ................................................................................................... 798

Document Info and Metadata. ..................................................................................... 799Zend_Pdf module usage example ................................................................................ 801

36. Zend_Registry ............................................................................................................ 805Using the Registry .................................................................................................... 805

xvi

Programmer's Reference Guide

Page 17: stacks on stacks on stacks

Setting Values in the Registry ............................................................................. 805Getting Values from the Registry ......................................................................... 805Constructing a Registry Object ........................................................................... 806Accessing the Registry as an Array ...................................................................... 806Accessing the Registry as an Object ..................................................................... 807Querying if an index exists ................................................................................. 807Extending the Registry ...................................................................................... 808Unsetting the Static Registry .............................................................................. 808

37. Zend_Rest ................................................................................................................. 810Introduction ............................................................................................................ 810Zend_Rest_Client ..................................................................................................... 810

Introduction .................................................................................................... 810Responses ....................................................................................................... 811Request Arguments ........................................................................................... 812

Zend_Rest_Server .................................................................................................... 813Introduction .................................................................................................... 813REST Server Usage .......................................................................................... 813Calling a Zend_Rest_Server Service .................................................................... 814Sending A Custom Status ................................................................................... 814Returning Custom XML Responses ..................................................................... 815

38. Zend_Search_Lucene ................................................................................................... 817Overview ................................................................................................................ 817

Introduction .................................................................................................... 817Document and Field Objects ............................................................................... 817Understanding Field Types ................................................................................. 819HTML documents ............................................................................................ 819

Building Indexes ...................................................................................................... 821Creating a New Index ........................................................................................ 821Updating Index ................................................................................................ 821Updating Documents ........................................................................................ 822Retrieving Index Size ........................................................................................ 822Index optimization ............................................................................................ 822Permissions ..................................................................................................... 824Limitations ..................................................................................................... 824

Searching an Index ................................................................................................... 825Building Queries .............................................................................................. 825Search Results ................................................................................................. 826Limiting the Result Set ...................................................................................... 827Results Scoring ................................................................................................ 828Search Result Sorting ........................................................................................ 828Search Results Highlighting ............................................................................... 829

Query Language ....................................................................................................... 829Terms ............................................................................................................. 830Fields ............................................................................................................. 830Wildcards ....................................................................................................... 831Term Modifiers ................................................................................................ 831Range Searches ................................................................................................ 831Fuzzy Searches ................................................................................................ 832Proximity Searches ........................................................................................... 832Boosting a Term ............................................................................................... 833Boolean Operators ............................................................................................ 833Grouping ........................................................................................................ 835Field Grouping ................................................................................................ 835Escaping Special Characters ............................................................................... 835

xvii

Programmer's Reference Guide

Page 18: stacks on stacks on stacks

Query Construction API ............................................................................................ 836Query Parser Exceptions .................................................................................... 836Term Query ..................................................................................................... 836Multi-Term Query ............................................................................................ 837Boolean Query ................................................................................................. 838Wildcard Query ............................................................................................... 840Fuzzy Query .................................................................................................... 841Phrase Query ................................................................................................... 842Range Query ................................................................................................... 845

Character Set ........................................................................................................... 846UTF-8 and single-byte character set support .......................................................... 846Default text analyzer ......................................................................................... 846UTF-8 compatible text analyzers ......................................................................... 846

Extensibility ............................................................................................................ 848Text Analysis ................................................................................................... 848Tokens Filtering ............................................................................................... 850Scoring Algorithms ........................................................................................... 851Storage Containers ........................................................................................... 853

Interoperating with Java Lucene .................................................................................. 855File Formats .................................................................................................... 855Index Directory ................................................................................................ 856Java Source Code ............................................................................................. 856

Advanced ............................................................................................................... 856Starting from 1.6, handling index format transformations. ........................................ 856Using the index as static property ........................................................................ 857

Best Practices .......................................................................................................... 858Field names ..................................................................................................... 858Indexing performance ....................................................................................... 859Index during Shut Down .................................................................................... 861Retrieving documents by unique id ...................................................................... 862Memory Usage ................................................................................................ 863Encoding ........................................................................................................ 863Index maintenance ............................................................................................ 864

39. Zend_Server ............................................................................................................... 866Introduction ............................................................................................................ 866Zend_Server_Reflection ............................................................................................ 866

Introduction .................................................................................................... 866Usage ............................................................................................................. 866

40. Zend_Service ............................................................................................................. 868Introduction ............................................................................................................ 868Zend_Service_Akismet ............................................................................................. 868

Introduction .................................................................................................... 868Verify an API key ............................................................................................. 869Check for spam ................................................................................................ 869Submitting known spam .................................................................................... 870Submitting false positives (ham) .......................................................................... 871Zend-specific Accessor Methods ......................................................................... 871

Zend_Service_Amazon ............................................................................................. 872Introduction .................................................................................................... 872Country Codes ................................................................................................. 873Looking up a Specific Amazon Item by ASIN ........................................................ 873Performing Amazon Item Searches ...................................................................... 874Using the Alternative Query API ......................................................................... 875Zend_Service_Amazon Classes ........................................................................... 875

xviii

Programmer's Reference Guide

Page 19: stacks on stacks on stacks

Zend_Service_Audioscrobbler .................................................................................... 881Introduction to Searching Audioscrobbler ............................................................. 881Users ............................................................................................................. 881Artists ............................................................................................................ 883Tracks ............................................................................................................ 884Tags ............................................................................................................... 884Groups ........................................................................................................... 884Forums ........................................................................................................... 885

Zend_Service_Delicious ............................................................................................ 885Introduction .................................................................................................... 885Retrieving posts ............................................................................................... 886Zend_Service_Delicious_PostList ....................................................................... 886Editing posts ................................................................................................... 888Deleting posts .................................................................................................. 888Adding new posts ............................................................................................. 889Tags ............................................................................................................... 890Bundles .......................................................................................................... 890Public data ...................................................................................................... 890HTTP client .................................................................................................... 891

Zend_Service_Flickr ................................................................................................. 892Introduction to Searching Flickr .......................................................................... 892Finding Flickr Users' Photos and Information ........................................................ 892Finding photos From a Group Pool ...................................................................... 893Retrieving Flickr Image Details ........................................................................... 893Zend_Service_Flickr Result Classes ..................................................................... 894

Zend_Service_Nirvanix ............................................................................................. 896Introduction .................................................................................................... 896Registering with Nirvanix .................................................................................. 896API Documentation .......................................................................................... 896Features .......................................................................................................... 896Getting Started ................................................................................................. 897Understanding the Proxy .................................................................................... 897Examining Results ............................................................................................ 898Handling Errors ............................................................................................... 899

Zend_Service_ReCaptcha .......................................................................................... 900Introduction .................................................................................................... 900Simplest use .................................................................................................... 900

Zend_Service_Simpy ................................................................................................ 901Introduction .................................................................................................... 901Links ............................................................................................................. 901Tags ............................................................................................................... 903Notes ............................................................................................................. 904Watchlists ....................................................................................................... 905

Introduction ............................................................................................................ 906Getting Started with Zend_Service_SlideShare ........................................... 906The SlideShow object ....................................................................................... 907Retrieving a single slide show ............................................................................. 910Retrieving Groups of Slide Shows ....................................................................... 910Zend_Service_SlideShare Caching policies ................................................ 911Changing the behavior of the HTTP Client ............................................................ 912

Zend_Service_StrikeIron ........................................................................................... 912Overview ........................................................................................................ 912Registering with StrikeIron ................................................................................ 913

xix

Programmer's Reference Guide

Page 20: stacks on stacks on stacks

Getting Started ................................................................................................. 913Making Your First Query ................................................................................... 914Examining Results ............................................................................................ 914Handling Errors ............................................................................................... 915Checking Your Subscription ............................................................................... 916

Zend_Service_StrikeIron: Bundled Services .................................................................. 917ZIP Code Information ....................................................................................... 917U.S. Address Verification ................................................................................... 918Sales & Use Tax Basic ...................................................................................... 918

Zend_Service_StrikeIron: Advanced Uses ..................................................................... 919Using Services by WSDL .................................................................................. 919Viewing SOAP Transactions ............................................................................... 920

Zend_Service_Technorati .......................................................................................... 921Introduction .................................................................................................... 921Getting Started ................................................................................................. 921Making Your First Query ................................................................................... 921Consuming Results ........................................................................................... 922Handling Errors ............................................................................................... 924Checking Your API Key Daily Usage ................................................................... 924Available Technorati Queries .............................................................................. 925Zend_Service_Technorati Classes ........................................................................ 929

Zend_Service_Yahoo ................................................................................................ 933Introduction .................................................................................................... 933Searching the Web with Yahoo! ........................................................................... 933Finding Images with Yahoo! ............................................................................... 934Finding videos with Yahoo! ................................................................................ 934Finding Local Businesses and Services with Yahoo! ................................................ 934Searching Yahoo! News ..................................................................................... 935Searching Yahoo! Site Explorer Inbound Links ...................................................... 935Searching Yahoo! Site Explorer's PageData ........................................................... 935Zend_Service_Yahoo Classes ............................................................................. 936

41. Zend_Session ............................................................................................................. 942Introduction ............................................................................................................ 942Basic Usage ............................................................................................................ 942

Tutorial Examples ............................................................................................ 943Iterating Over Session Namespaces ...................................................................... 944Accessors for Session Namespaces ...................................................................... 944

Advanced Usage ...................................................................................................... 945Starting a Session ............................................................................................. 945Locking Session Namespaces ............................................................................. 946Namespace Expiration ....................................................................................... 947Session Encapsulation and Controllers ................................................................. 947Preventing Multiple Instances per Namespace ........................................................ 948Working with Arrays ......................................................................................... 949Using Sessions with Objects ............................................................................... 951Using Sessions with Unit Tests ........................................................................... 951

Global Session Management ....................................................................................... 953Configuration Options ....................................................................................... 953Error: Headers Already Sent ............................................................................... 956Session Identifiers ............................................................................................ 956rememberMe(integer $seconds) ............................................................. 958forgetMe() ................................................................................................. 958sessionExists() ....................................................................................... 958

xx

Programmer's Reference Guide

Page 21: stacks on stacks on stacks

destroy(bool $remove_cookie = true, bool $readonly =true) ........................................................................................................... 958stop() ......................................................................................................... 959writeClose($readonly = true) ............................................................. 959expireSessionCookie() ........................................................................... 959setSaveHandler(Zend_Session_SaveHandler_Interface $inter-face) ........................................................................................................... 959namespaceIsset($namespace) ................................................................. 959namespaceUnset($namespace) ................................................................. 960namespaceGet($namespace) ..................................................................... 960getIterator() ........................................................................................... 960

Zend_Session_SaveHandler_DbTable .......................................................................... 96042. Zend_Soap ................................................................................................................. 963

Zend_Soap_Server ................................................................................................... 963Zend_Soap_Server constructor. .................................................................... 963Methods to define Web Service API. .................................................................... 964Request and response objects handling. ................................................................ 965

Zend_Soap_Client .................................................................................................... 967Zend_Soap_Client Constructor .................................................................... 967Performing SOAP Requests ................................................................................ 968

WSDL Accessor ....................................................................................................... 970Zend_Soap_Wsdl constructor. ........................................................................ 970addMessage() method. ................................................................................. 970addPortType() method. ............................................................................... 971addPortOperation() method. ..................................................................... 971addBinding() method. ................................................................................. 971addBindingOperation() method. ............................................................... 971addSoapBinding() method. ......................................................................... 972addSoapOperation() method. ..................................................................... 972addService() method. ................................................................................. 972Type mapping. ................................................................................................. 973addDocumentation() method. ..................................................................... 974Get finilised WSDL document. ........................................................................... 974

AutoDiscovery. ........................................................................................................ 974AutoDiscovery. Introduction ............................................................................... 974Class autodiscovering. ....................................................................................... 975Functions autodiscovering. ................................................................................. 976Autodiscovering. Datatypes. ............................................................................... 977

43. Zend_Test .................................................................................................................. 978Introduction ............................................................................................................ 978Zend_Test_PHPUnit ................................................................................................. 978

Bootstrapping your TestCase .............................................................................. 980Testing your Controllers and MVC Applications ..................................................... 981Assertions ....................................................................................................... 983Examples ........................................................................................................ 985

44. Zend_Text ................................................................................................................. 991Zend_Text_Figlet ..................................................................................................... 991

45. Zend_TimeSync .......................................................................................................... 993Introduction ............................................................................................................ 993

Why Zend_TimeSync ? ................................................................................. 993What is NTP ? ................................................................................................. 994What is SNTP? ................................................................................................ 994Problematic usage ............................................................................................ 994

xxi

Programmer's Reference Guide

Page 22: stacks on stacks on stacks

Decide which server to use ................................................................................. 994Working with Zend_TimeSync .................................................................................... 995

Generic timeserver request ................................................................................. 995Multiple timeservers ......................................................................................... 995Protocols of timeservers .................................................................................... 996Using ports for timeservers ................................................................................. 996Options for timeservers ..................................................................................... 997Using different timeservers ................................................................................ 997Informations from timeservers ............................................................................ 998Taking care of exceptions ................................................................................... 998

46. Zend_Translate ........................................................................................................... 999Introduction ............................................................................................................ 999

Starting multi-lingual ........................................................................................ 999Adapters for Zend_Translate ..................................................................................... 1000

How to decide which translation adapter to use ..................................................... 1000Integrate self written Adapters ........................................................................... 1002Speedup all Adapters ....................................................................................... 1003

Using Translation Adapters ....................................................................................... 1003Translation Source Structures ............................................................................ 1005Creating array source files ................................................................................ 1007Creating Gettext Source Files ............................................................................ 1008Creating TMX Source Files .............................................................................. 1009Creating CSV Source Files ............................................................................... 1009Creating INI Source Files ................................................................................. 1010Options for adapters ........................................................................................ 1011Handling languages ......................................................................................... 1012Automatic source detection ............................................................................... 1015Checking for translations ................................................................................. 1018Access to the source data ................................................................................. 1019

47. Zend_Uri ................................................................................................................. 1021Zend_Uri .............................................................................................................. 1021

Overview ...................................................................................................... 1021Creating a New URI ........................................................................................ 1021Manipulating an Existing URI ........................................................................... 1021URI Validation ............................................................................................... 1022Common Instance Methods .............................................................................. 1022

48. Zend_Validate ........................................................................................................... 1024Introduction ........................................................................................................... 1024

What is a validator? ........................................................................................ 1024Basic usage of validators .................................................................................. 1024Customizing messages ..................................................................................... 1025Using the static is() method ........................................................................... 1026

Standard Validation Classes ...................................................................................... 1027Alnum .......................................................................................................... 1027Alpha ........................................................................................................... 1027Barcode ........................................................................................................ 1027Between ........................................................................................................ 1027Ccnum .......................................................................................................... 1027Date ............................................................................................................. 1027Digits ........................................................................................................... 1027EmailAddress ................................................................................................ 1027Float ............................................................................................................ 1029GreaterThan .................................................................................................. 1030Hex .............................................................................................................. 1030

xxii

Programmer's Reference Guide

Page 23: stacks on stacks on stacks

Hostname ...................................................................................................... 1030InArray ......................................................................................................... 1032Int ............................................................................................................... 1032Ip ................................................................................................................ 1032LessThan ...................................................................................................... 1032NotEmpty ..................................................................................................... 1032Regex ........................................................................................................... 1032StringLength .................................................................................................. 1033

Validator Chains ..................................................................................................... 1033Writing Validators ................................................................................................... 1034

49. Zend_Version ........................................................................................................... 1040Reading the Zend Framework Version ......................................................................... 1040

50. Zend_View ............................................................................................................... 1041Introduction ........................................................................................................... 1041

Controller Script ............................................................................................. 1041View Script ................................................................................................... 1041Options ......................................................................................................... 1042Short Tags with View Scripts ............................................................................. 1043Utility Accessors ............................................................................................ 1044

Controller Scripts ................................................................................................... 1044Assigning Variables ......................................................................................... 1044Rendering a View Script ................................................................................... 1045View Script Paths ........................................................................................... 1045

View Scripts .......................................................................................................... 1046Escaping Output ............................................................................................. 1047Using Alternate Template Systems ..................................................................... 1048

View Helpers ......................................................................................................... 1053Initial Helpers ................................................................................................ 1054Helper Paths .................................................................................................. 1081Writing Custom Helpers .................................................................................. 1082

Zend_View_Abstract ............................................................................................... 108451. Zend_Wildfire .......................................................................................................... 1085

Zend_Wildfire ....................................................................................................... 108552. Zend_XmlRpc .......................................................................................................... 1086

Introduction ........................................................................................................... 1086Zend_XmlRpc_Client .............................................................................................. 1086

Introduction ................................................................................................... 1086Method Calls ................................................................................................. 1086Types and Conversions .................................................................................... 1087Server Proxy Object ........................................................................................ 1089Error Handling ............................................................................................... 1090Server Introspection ........................................................................................ 1091From Request to Response ............................................................................... 1091HTTP Client and Testing .................................................................................. 1092

Zend_XmlRpc_Server ............................................................................................. 1092Introduction ................................................................................................... 1092Basic Usage ................................................................................................... 1092Server Structure ............................................................................................. 1093Conventions .................................................................................................. 1093Utilizing Namespaces ...................................................................................... 1094Custom Request Objects .................................................................................. 1094Custom Responses .......................................................................................... 1095Handling Exceptions via Faults ......................................................................... 1095Caching Server Definitions Between Requests ..................................................... 1095

xxiii

Programmer's Reference Guide

Page 24: stacks on stacks on stacks

Usage Examples ............................................................................................. 1096A. Zend Framework Requirements ..................................................................................... 1100

PHP Version .......................................................................................................... 1100PHP Extensions ...................................................................................................... 1100Zend Framework Components ................................................................................... 1106Zend Framework Dependencies ................................................................................. 1111

B. Zend Framework Coding Standard for PHP ..................................................................... 1119Overview .............................................................................................................. 1119

Scope ........................................................................................................... 1119Goals ........................................................................................................... 1119

PHP File Formatting ............................................................................................... 1119General ......................................................................................................... 1119Indentation .................................................................................................... 1119Maximum Line Length .................................................................................... 1120Line Termination ............................................................................................ 1120

Naming Conventions ............................................................................................... 1120Classes ......................................................................................................... 1120Filenames ..................................................................................................... 1120Functions and Methods .................................................................................... 1121Variables ....................................................................................................... 1121Constants ...................................................................................................... 1122

Coding Style .......................................................................................................... 1122PHP Code Demarcation ................................................................................... 1122Strings .......................................................................................................... 1122Arrays .......................................................................................................... 1123Classes ......................................................................................................... 1124Functions and Methods .................................................................................... 1125Control Statements .......................................................................................... 1127Inline Documentation ...................................................................................... 1128

C. Copyright Information ................................................................................................. 1131Index ............................................................................................................................ 1132

xxiv

Programmer's Reference Guide

Page 25: stacks on stacks on stacks

List of Tables2.1. Access Controls for an Example CMS ................................................................................ 53.1. Configuration Options ................................................................................................... 273.2. Server Options ............................................................................................................. 343.3. Debugging Messages .................................................................................................... 353.4. Options for Active Directory .......................................................................................... 363.5. Options for OpenLDAP ................................................................................................. 374.1. Core frontend options ................................................................................................... 454.2. Function frontend options .............................................................................................. 484.3. Class frontend options ................................................................................................... 494.4. File frontend options ..................................................................................................... 514.5. Page frontend options ................................................................................................... 534.6. File backend options ..................................................................................................... 564.7. Sqlite backend options .................................................................................................. 574.8. Memcached backend options .......................................................................................... 574.9. Xcache backend options ................................................................................................ 586.1. Zend_Config_Ini Constructor parameters ......................................................................... 679.1. Constants for the selecting the currency description ........................................................... 1899.2. Constants for the selecting the currency position ............................................................... 18910.1. Date Parts ................................................................................................................ 20310.2. Basic Operations ...................................................................................................... 20510.3. Date Comparison Methods ......................................................................................... 20610.4. Date Output Methods ................................................................................................ 20710.5. Date Output Methods ................................................................................................ 20810.6. Miscellaneous Methods .............................................................................................. 20810.7. Operations involving Zend_Date::HOUR ...................................................................... 21110.8. Day Constants .......................................................................................................... 21210.9. Week Constants ........................................................................................................ 21210.10. Month Constants ..................................................................................................... 21310.11. Year Constants ........................................................................................................ 21310.12. Time Constants ....................................................................................................... 21410.13. Timezone Constants ................................................................................................. 21410.14. Date Format Constants (formats include timezone) ........................................................ 21510.15. Date and Time Formats (format varies by locale) ........................................................... 21610.16. Constants for ISO 8601 date output .......................................................................... 21810.17. Constants for PHP date output ................................................................................ 22110.18. Types of supported horizons for sunset and sunrise ........................................................ 22511.1. Metadata fields returned by describeTable() ................................................................... 24811.2. Constants used by getPart() and reset() .......................................................................... 28020.1. Metadata used in the code-sample below ....................................................................... 56621.1. Zend_Http_Client configuration parameters ................................................................... 58421.2. Zend_Http_Client_Adapter_Socket configuration parameters ............................................ 59321.3. Zend_Http_Client configuration parameters ................................................................... 59425.1. Zend_Ldap Options ................................................................................................... 64125.2. accountCanonicalForm ..................................................................................... 64227.1. Details for getTranslationList($type = null, $locale = null, $value = null) ............................ 66027.2. Details for getTranslation($value = null, $type = null, $locale = null) .................................. 66427.3. Differences between ZF 1.0 and ZF 1.5 ......................................................................... 66727.4. Format tokens for self generated number formats ........................................................... 67327.5. List of supported numeral systems ............................................................................... 67827.6. Key values for getDate() with option 'fix_date' ............................................................... 67927.7. Return values ........................................................................................................... 679

xxv

Page 26: stacks on stacks on stacks

27.8. Format definition ...................................................................................................... 68227.9. Example formats ...................................................................................................... 68227.10. List of all supported languages ................................................................................... 68528.1. Firebug Logging Styles .............................................................................................. 70229.1. Mail Read Feature Overview ....................................................................................... 71529.2. Mail Folder Names ................................................................................................... 72230.1. List of measurement types .......................................................................................... 73634.1. Adapters for Zend_Paginator ................................................................................ 77034.2. Scrolling styles for Zend_Paginator ....................................................................... 77234.3. Properties available to view partials .............................................................................. 77534.4. Configuration methods for Zend_Paginator ............................................................. 77538.1. Zend_Search_Lucene_Field Types ............................................................................... 81940.1. Zend_Service_Amazon_Item Properties ........................................................................ 87740.2. Zend_Service_Amazon_Image Properties ...................................................................... 87740.3. Zend_Service_Amazon_OfferSet Properties .................................................................. 87840.4. Properties ................................................................................................................ 87940.5. Zend_Service_Amazon_SimilarProduct Properties .......................................................... 87940.6. Zend_Service_Amazon_Accessories Properties .............................................................. 87940.7. Zend_Service_Amazon_CustomerReview Properties ....................................................... 88040.8. Zend_Service_Amazon_EditorialReview Properties ........................................................ 88040.9. Zend_Service_Amazon_Listmania Properties ................................................................. 88040.10. Methods for retrieving public data .............................................................................. 89040.11. Methods of the Zend_Service_Delicious_SimplePost class ............................. 89140.12. Zend_Service_Flickr_ResultSet Properties ................................................................... 89440.13. Zend_Service_Flickr_Result Properties ....................................................................... 89540.14. Zend_Service_Flickr_Image Properties ....................................................................... 89540.15. Zend_Service_Yahoo_ResultSet ................................................................................ 93740.16. Zend_Service_Yahoo_LocalResultSet Properties ........................................................... 93840.17. Zend_Service_Yahoo_Result Properties ...................................................................... 93940.18. Zend_Service_Yahoo_WebResult Properties ................................................................ 93940.19. Zend_Service_Yahoo_ImageResult Properties .............................................................. 93940.20. Zend_Service_Yahoo_VideoResult Properties .............................................................. 94040.21. Zend_Service_Yahoo_LocalResult Properties ............................................................... 94040.22. Zend_Service_Yahoo_NewsResult Properties ............................................................... 94140.23. Zend_Service_Yahoo_Image Properties ....................................................................... 94146.1. Adapters for Zend_Translate ..................................................................................... 100046.2. Options for Translation Adapters ................................................................................ 101252.1. PHP and XML-RPC Type Conversions ........................................................................ 108752.2. Zend_XmlRpc_Value Objects for XML-RPC Types .................................................. 1089A.1. PHP Extensions Used in Zend Framework by Component ................................................ 1101A.2. Zend Framework Components and the PHP Extensions they use ....................................... 1107A.3. Zend Framework Components and their dependency to other Zend Framework Compon-ents .............................................................................................................................. 1112

xxvi

Programmer's Reference Guide

Page 27: stacks on stacks on stacks

List of Examples2.1. Multiple Inheritance amoung Roles ................................................................................... 43.1. Modifying the Session Namespace .................................................................................. 163.2. Using a Custom Storage Class ........................................................................................ 173.3. Basic Usage ................................................................................................................ 214.1. Getting a frontend with Zend_Cache::factory() ....................................................... 404.2. Caching a database query result ...................................................................................... 414.3. Caching output with Zend_Cache output frontend ........................................................... 426.1. Using Zend_Config Per Se ............................................................................................. 636.2. Using Zend_Config with a PHP Configuration File ............................................................. 646.3. Using Zend_Config_Ini ................................................................................................. 666.4. Using Zend_Config_Xml ............................................................................................... 686.5. Using tag attributes in Zend_Config_Xml ......................................................................... 697.1. Using the Short Syntax .................................................................................................. 717.2. Using the Long Syntax .................................................................................................. 727.3. Catching Getopt Exceptions ........................................................................................... 737.4. Using getOption() ........................................................................................................ 737.5. Using __get() and __isset() magic methods ....................................................................... 737.6. Using getRemainingArgs() ............................................................................................. 747.7. Using addRules() ......................................................................................................... 757.8. Using setHelp() ........................................................................................................... 757.9. Using setAliases() ........................................................................................................ 767.10. Using addArguments() and setArguments() ..................................................................... 767.11. Using setOption() ....................................................................................................... 777.12. Using setOptions() ...................................................................................................... 778.1. How to Handle Non-Existent Actions ............................................................................. 1188.2. Adding a task using action, controller and module names ................................................... 1238.3. Adding a task using a request object ............................................................................... 1248.4. AutoCompletion with Dojo Using Zend MVC .................................................................. 1278.5. Allowing Actions to Respond To Ajax Requests ................................................................ 1378.6. Setting Options .......................................................................................................... 1418.7. Using Defaults ........................................................................................................... 1428.8. Using goto()'s _forward() API ....................................................................................... 1438.9. Using route assembly with gotoRoute() .......................................................................... 1448.10. Basic Usage ............................................................................................................. 1518.11. Disabling autorender ................................................................................................. 1528.12. Choosing a different view script ................................................................................... 1538.13. Modifying the registered view ..................................................................................... 1548.14. Changing the path specifications .................................................................................. 1558.15. Rendering multiple view scripts from a single action ....................................................... 1568.16. Standard usage ......................................................................................................... 1688.17. Setting a different error handler ................................................................................... 1688.18. Using accessors ........................................................................................................ 1689.1. Creating an instance of Zend_Currency from the actual locale ............................................. 1859.2. Other examples for creating an instance of Zend_Currency ................................................. 1879.3. Creating output for an currency ..................................................................................... 1889.4. Changing the displayed format of a currency ................................................................... 1909.5. Getting informations from currencies ............................................................................. 1919.6. Setting a new locale .................................................................................................... 1919.7. Caching currencies ..................................................................................................... 19210.1. Setting a default timezone .......................................................................................... 19410.2. Creating the current date ............................................................................................ 196

xxvii

Page 28: stacks on stacks on stacks

10.3. get() - output a date ................................................................................................... 19710.4. set() - set a date ........................................................................................................ 19710.5. add() - adding dates ................................................................................................... 19710.6. compare() - compare dates .......................................................................................... 19810.7. equals() - identify a date or date part ............................................................................. 19810.8. User-specified input date format .................................................................................. 20010.9. Operating on Parts of Dates ........................................................................................ 20110.10. Date creation by instance .......................................................................................... 20810.11. Static date creation .................................................................................................. 20910.12. Quick creation of dates from database date values ......................................................... 20910.13. Convenient creation of dates from database date values .................................................. 20910.14. Date creation by array .............................................................................................. 21010.15. Example usage for self-defined ISO formats ................................................................. 21710.16. Example usage for self-defined formats with PHP specifier ............................................. 22010.17. Checking dates ....................................................................................................... 22410.18. Getting all available cities ......................................................................................... 22410.19. Getting the location for a city .................................................................................... 22510.20. Calculating sun informations ..................................................................................... 22610.21. Working with timezones ........................................................................................... 22710.22. Multiple timezones .................................................................................................. 22811.1. Using an Adapter constructor ...................................................................................... 23011.2. Using the Adapter factory method ................................................................................ 23011.3. Using the Adapter factory method for a custom adapter class ............................................. 23111.4. Using the Adapter factory method with a Zend_Config object ........................................... 23111.5. Passing the case-folding option to the factory ................................................................. 23211.6. Passing the auto-quoting option to the factory ................................................................ 23311.7. Passing PDO driver options to the factory ...................................................................... 23311.8. Handling connection exceptions .................................................................................. 23411.9. Using fetchAll() ....................................................................................................... 23611.10. Using setFetchMode() .............................................................................................. 23711.11. Using fetchAssoc() .................................................................................................. 23711.12. Using fetchCol() ..................................................................................................... 23811.13. Using fetchPairs() ................................................................................................... 23811.14. Using fetchRow() .................................................................................................... 23811.15. Using fetchOne() .................................................................................................... 23911.16. Inserting to a table ................................................................................................... 23911.17. Inserting expressions to a table .................................................................................. 24011.18. Using lastInsertId() for an auto-increment key .............................................................. 24011.19. Using lastInsertId() for a sequence .............................................................................. 24011.20. Using lastSequenceId() ............................................................................................ 24111.21. Updating rows ........................................................................................................ 24211.22. Updating rows using an array of expressions ................................................................ 24211.23. Deleting rows ......................................................................................................... 24311.24. Using quote() ......................................................................................................... 24411.25. Using quote() with a SQL type .................................................................................. 24411.26. Using quoteInto() .................................................................................................... 24511.27. Using quoteInto() with a SQL type ............................................................................. 24511.28. Using quoteIdentifier() ............................................................................................. 24611.29. Managing a transaction to ensure consistency ............................................................... 24711.30. Closing a database connection ................................................................................... 24911.31. Running a non-prepared statement in a PDO adapter ...................................................... 24911.32. Creating a SQL statement object with query() ............................................................... 25211.33. Using a SQL statement constructor ............................................................................. 25311.34. Executing a statement with positional parameters .......................................................... 253

xxviii

Programmer's Reference Guide

Page 29: stacks on stacks on stacks

11.35. Executing a statement with named parameters .............................................................. 25311.36. Using fetch() in a loop ............................................................................................. 25411.37. Using fetchAll() ...................................................................................................... 25411.38. Setting the fetch mode .............................................................................................. 25511.39. Using fetchColumn() ............................................................................................... 25511.40. Using fetchObject() ................................................................................................. 25611.41. DB Profiling with Zend_Controller_Front ......................................................... 26111.42. DB Profiling without Zend_Controller_Front .................................................... 26211.43. Example of the database adapter's select() method ......................................................... 26311.44. Example of creating a new Select object ...................................................................... 26311.45. Example of the using methods to add clauses ................................................................ 26311.46. Example of the using the fluent interface ..................................................................... 26411.47. Example of the from() method ................................................................................... 26411.48. Example of specifying a table correlation name ............................................................. 26411.49. Example of specifying a schema name ........................................................................ 26511.50. Examples of specifying columns ................................................................................ 26611.51. Examples of specifying columns containing expressions ................................................. 26711.52. Examples of quoting columns in an expression ............................................................. 26811.53. Examples of adding columns with the columns() method ............................................ 26811.54. Example of the join() method .................................................................................... 26911.55. Example of specifying no columns ............................................................................. 26911.56. Example of the joinUsing() method ............................................................................ 27111.57. Example of the where() method ................................................................................. 27111.58. Example of a parameter in the where() method ............................................................. 27211.59. Example of multiple where() methods ......................................................................... 27211.60. Example of the orWhere() method .............................................................................. 27311.61. Example of parenthesizing Boolean expressions ............................................................ 27311.62. Example of the group() method .................................................................................. 27411.63. Example of the having() method ................................................................................ 27511.64. Example of the order() method .................................................................................. 27611.65. Example of the limit() method ................................................................................... 27611.66. Example of the limitPage() method ............................................................................. 27711.67. Example of the distinct() method ................................................................................ 27711.68. Example of forUpdate() method ................................................................................. 27811.69. Example using the Db adapter's query() method ............................................................ 27811.70. Example using the Select object's query method ............................................................ 27811.71. Example of the __toString() method ........................................................................... 27911.72. Example of the getPart() method ................................................................................ 28011.73. Example of the reset() method ................................................................................... 28111.74. Declaring a table class with explicit table name ............................................................. 28211.75. Declaring a table class with implicit table name ............................................................ 28211.76. Declaring a table class with schema ............................................................................ 28211.77. Declaring table and schema names upon instantiation ..................................................... 28311.78. Example of specifying the primary key ........................................................................ 28311.79. Example of overriding the _setupTableName() method ................................................... 28411.80. Example usage of init() method ................................................................................. 28511.81. Example of constructing a Table using an Adapter object ................................................ 28511.82. Example of constructing a Table using a the Default Adapter ........................................... 28611.83. Example of constructing a Table using a Registry key .................................................... 28611.84. Example of inserting to a Table .................................................................................. 28711.85. Example of inserting expressions to a Table .................................................................. 28711.86. Example of declaring a Table with auto-incrementing primary key .................................... 28811.87. Example of declaring a Table with a sequence .............................................................. 288

xxix

Programmer's Reference Guide

Page 30: stacks on stacks on stacks

11.88. Example of declaring a Table with a natural key ............................................................ 28911.89. Example of updating rows in a Table ........................................................................... 28911.90. Example of deleting rows from a Table ........................................................................ 29011.91. Example of finding rows by primary key values ............................................................ 29111.92. Example of finding rows by compound primary key values ............................................. 29211.93. Simple usage .......................................................................................................... 29311.94. Example of fluent interface ....................................................................................... 29311.95. Example of finding rows by an expression ................................................................... 29411.96. Example of finding rows by an expression ................................................................... 29411.97. Retrieving specific columns ...................................................................................... 29511.98. Retrieving expressions as columns .............................................................................. 29511.99. Using a lookup table to refine the results of fetchAll() .................................................... 29511.100. Removing the integrity check on Zend_Db_Table_Select to allow JOINed rows ................ 29611.101. Example of finding a single row by an expression ........................................................ 29611.102. Example of getting the table name ............................................................................ 29711.103. Using a Default Metadata Cache for all Table Objects ................................................... 29811.104. Using a Metadata Cache for a Specific Table Object ..................................................... 29911.105. Example of specifying the Row and Rowset classes ..................................................... 30011.106. Example of changing the Row and Rowset classes ....................................................... 30011.107. Custom logic to manage timestamps ......................................................................... 30111.108. Custom method to find bugs by status ........................................................................ 30211.109. Example of an abstract table class that implements inflection ......................................... 30311.110. Example of fetching a row ....................................................................................... 30311.111. Example of reading a row in a rowset ........................................................................ 30411.112. Example of reading a column in a row ....................................................................... 30411.113. Example of using the toArray() method ..................................................................... 30511.114. Example of changing a column in a row ..................................................................... 30511.115. Example of creating a new row for a table .................................................................. 30611.116. Example of populating a new row for a table ............................................................... 30611.117. Example of using setFromArray() to set values in a new Row ........................................ 30711.118. Example of deleting a row ....................................................................................... 30711.119. Example of serializing a row .................................................................................... 30811.120. Example of unserializing a serialized row ................................................................... 30811.121. Example of reactivating a row .................................................................................. 30911.122. Specifying a custom Row class ................................................................................ 30911.123. Example usage of init() method ................................................................................ 31011.124. Example of custom logic in a Row class .................................................................... 31111.125. Example of a Row class that logs insert data for multiple tables ...................................... 31211.126. Example of defining an inflection transformation ......................................................... 31311.127. Example of fetching a rowset ................................................................................... 31411.128. Counting the Rows in a Rowset ................................................................................ 31411.129. Reading a Single Row from a Rowset ........................................................................ 31411.130. Iterating through a Rowset ...................................................................................... 31511.131. Seeking to a known position into a Rowset ................................................................. 31511.132. Using toArray() ..................................................................................................... 31611.133. Serializing a Rowset .............................................................................................. 31711.134. Unserializing a Serialized Rowset ............................................................................. 31711.135. Reactivating a Rowset as Live Data ........................................................................... 31811.136. Specifying a custom Rowset class ............................................................................. 31811.137. Example of Rowset class with a new method .............................................................. 31911.138. Fetching a Dependent Rowset .................................................................................. 32211.139. Fetching a Dependent Rowset By a Specific Rule ........................................................ 32211.140. Fetching a Dependent Rowset using a Zend_Db_Table_Select ....................................... 32311.141. Fetching Dependent Rowsets using the Magic Method ................................................. 324

xxx

Programmer's Reference Guide

Page 31: stacks on stacks on stacks

11.142. Fetching the Parent Row ......................................................................................... 32411.143. Fetching a Parent Row By a Specific Rule .................................................................. 32511.144. Fetching the Parent Row using the Magic Method ........................................................ 32511.145. Fetching a Rowset with the Many-to-many Method ...................................................... 32611.146. Fetching a Rowset with the Many-to-many Method By a Specific Rule ............................ 32711.147. Fetching Rowsets using the Magic Many-to-many Method ............................................ 32811.148. Example of a Cascading Delete ................................................................................ 32911.149. Example Declaration of Cascading Operations ............................................................ 33012.1. Example of dump() method ........................................................................................ 33213.1. Zend_Dojo_Data initialization via constructor ................................................................ 33413.2. Zend_Dojo_Data initialization via mutators ................................................................... 33413.3. Appending data to Zend_Dojo_Data ............................................................................. 33413.4. Specifying a label field in Zend_Dojo_Data ................................................................... 33513.5. Populating Zend_Dojo_Data from JSON ....................................................................... 33513.6. Using Dojo View Helpers ........................................................................................... 33713.7. dojo() View Helper Usage Example .............................................................................. 33813.8. Specifying Declarative and Programmatic Dojo Usage ..................................................... 34013.9. Registering the Dojo View Helper Prefix Path ................................................................ 34413.10. BorderContainer layout dijit example .......................................................................... 34713.11. Enabling Dojo in your existing forms .......................................................................... 35613.12. DijitElement Decorator Usage ................................................................................... 35713.13. DijitContainer Decorator Usage ................................................................................. 35813.14. Example Button dijit element usage ............................................................................ 35913.15. Example CheckBox dijit element usage ....................................................................... 36013.16. ComboBox dijit element usage as select input ............................................................... 36113.17. ComboBox dijit element usage with datastore ............................................................... 36113.18. Example CurrencyTextBox dijit element usage ............................................................. 36213.19. Example DateTextBox dijit element usage ................................................................... 36313.20. Example HorizontalSlider dijit element usage ............................................................... 36513.21. Example NumberSpinner dijit element usage ................................................................ 36613.22. Example NumberTextBox dijit element usage ............................................................... 36713.23. Example PasswordTextBox dijit element usage ............................................................. 36813.24. Example RadioButton dijit element usage .................................................................... 36813.25. Example SubmitButton dijit element usage .................................................................. 36913.26. Example TextBox dijit element usage .......................................................................... 37013.27. Example Textarea dijit element usage .......................................................................... 37013.28. Example TimeTextBox dijit element usage ................................................................... 37113.29. Example ValidationTextBox dijit element usage ............................................................ 37213.30. Example VerticalSlider dijit element usage ................................................................... 37313.31. Using Zend_Dojo_Form ........................................................................................... 37513.32. Modifying an existing form to utilize Dojo ................................................................... 38115.1. Example of catching an exception ................................................................................ 38516.1. Putting Zend_Feed to Work on RSS Feed Data ............................................................... 38716.2. Basic Use of an Atom Feed ......................................................................................... 39416.3. Reading a Single-Entry Atom Feed .............................................................................. 39516.4. Using the Entry Object Directly for a Single-Entry Atom Feed .......................................... 39516.5. Modifying an Existing Feed Entry ................................................................................ 39516.6. Creating an Atom Entry with Elements of Custom Namespaces ......................................... 39616.7. Extending the Atom Entry Class with Custom Namespaces ............................................... 39717.1. Simple File-Upload Form ........................................................................................... 40017.2. Add validators to a file transfer .................................................................................... 40217.3. Limit validators to single files ..................................................................................... 40217.4. Add multiple validators .............................................................................................. 40217.5. Using the Count validator ........................................................................................... 403

xxxi

Programmer's Reference Guide

Page 32: stacks on stacks on stacks

17.6. Using the Exists validator ........................................................................................... 40417.7. Using the Extension validator ...................................................................................... 40517.8. Using the FilesSize validator ....................................................................................... 40617.9. Using the ImageSize validator ..................................................................................... 40717.10. Using the MimeType validator ................................................................................... 40717.11. Using the NotExists validator .................................................................................... 40817.12. Using the Size validator ............................................................................................ 40918.1. Transforming MixedCase and camelCaseText to another format ........................................ 42618.2. Setting Multiple Rules at Once .................................................................................... 43018.3. Using Zend_Config with Zend_Filter_Inflector .............................................................. 43119.1. Custom Label ........................................................................................................... 44219.2. Setting Prefix Paths for All Elements ............................................................................ 46119.3. Setting Decorators for All Elements .............................................................................. 46219.4. Setting Decorators for Some Elements .......................................................................... 46319.5. Setting Filters for All Elements .................................................................................... 46419.6. Setting Decorator Prefix Path for All Display Groups ....................................................... 46619.7. Setting Decorators for All Display Groups ..................................................................... 46619.8. File form element usage ............................................................................................. 48919.9. Registration Form Example ........................................................................................ 50421.1. Instantiating a Zend_Http_Client object ........................................................................ 58321.2. Performing a Simple GET Request ............................................................................... 58421.3. Using Request Methods Other Than GET ...................................................................... 58521.4. Setting GET Parameters ............................................................................................. 58521.5. Setting POST Parameters ........................................................................................... 58621.6. Forcing RFC 2616 Strict Redirections on 301 and 302 Responses ...................................... 58621.7. Setting Cookies Using setCookie() ............................................................................... 58721.8. Enabling Cookie Stickiness ........................................................................................ 58821.9. Setting A Single Custom Request Header ...................................................................... 58821.10. Setting Multiple Custom Request Headers ................................................................... 58921.11. Using setFileUpload to Upload Files ........................................................................... 58921.12. Sending Raw POST Data .......................................................................................... 59021.13. Setting HTTP Authentication User and Password .......................................................... 59121.14. Performing consecutive requests with one client ............................................................ 59221.15. Changing the HTTPS transport layer ........................................................................... 59421.16. Using Zend_Http_Client behind a proxy server ............................................................. 59521.17. Testing Against a Single HTTP Response Stub .............................................................. 59621.18. Testing Against Multiple HTTP Response Stubs ............................................................ 59721.19. Creating your own connection adapter ......................................................................... 59921.20. Instantiating a Zend_Http_Cookie object ..................................................................... 60121.21. Stringifying a Zend_Http_Cookie object ...................................................................... 60221.22. Using getter methods with Zend_Http_Cookie .............................................................. 60321.23. Matching cookies .................................................................................................... 60421.24. Instantiating a Zend_Http_Response object using the factory method ................................ 60721.25. Using the isError() method to validate a response .......................................................... 60821.26. Using Zend_Http_Response Accessor Methods ............................................................. 60821.27. Accessing Response Headers ..................................................................................... 60923.1. Zend_Json_Server Usage ........................................................................................... 62124.1. Passing options to the constructor or startMvc() .............................................................. 63424.2. Using setOption() and setConfig() ................................................................................ 63524.3. Using Accessors ....................................................................................................... 63524.4. Using Zend_Layout accessors to modify the inflector ...................................................... 63724.5. Direct modification of Zend_Layout inflector ................................................................. 63724.6. Custom inflectors ...................................................................................................... 63826.1. Example of loadFile() method ..................................................................................... 644

xxxii

Programmer's Reference Guide

Page 33: stacks on stacks on stacks

26.2. Example of loadClass() method ................................................................................... 64526.3. Example of isReadable() method ................................................................................. 64526.4. Example of registering the autoloader callback method .................................................... 64626.5. Example of registering the autoload callback method from an extended class ....................... 64627.1. Choosing a specific locale .......................................................................................... 65127.2. Automatically selecting a locale ................................................................................... 65227.3. Using automatic locales ............................................................................................. 65327.4. Handling locale exceptions ......................................................................................... 65427.5. Setting a default locale ............................................................................................... 65427.6. Dates default to correct locale of web users .................................................................... 65427.7. Overriding default locale selection ............................................................................... 65527.8. Performance optimization when using a default locale ..................................................... 65527.9. Usage of an application wide locale .............................................................................. 65527.10. Dates default to correct locale of web users .................................................................. 65627.11. Using STANDARD definitions for setOptions() ............................................................ 65627.12. clone .................................................................................................................... 65727.13. Check for equal locales ............................................................................................ 65727.14. Get default locales ................................................................................................... 65827.15. setLocale ............................................................................................................... 65827.16. getLanguage and getRegion ...................................................................................... 65927.17. getTranslationList ................................................................................................... 65927.18. getTranslationList ................................................................................................... 66827.19. Converting country name in one language to another ...................................................... 66827.20. All available translations ........................................................................................... 66827.21. All Languages written in their native language .............................................................. 66927.22. getQuestion() ......................................................................................................... 67027.23. getLocaleList() ....................................................................................................... 67027.24. Number normalization ............................................................................................. 67127.25. Number normalization with precision .......................................................................... 67227.26. Number localization ................................................................................................ 67227.27. Number localization with precision ............................................................................. 67327.28. Using a self defined number format ............................................................................ 67327.29. Number testing ....................................................................................................... 67427.30. Floating point value normalization .............................................................................. 67427.31. Floating point value localization ................................................................................. 67527.32. Floating point value testing ....................................................................................... 67527.33. Integer value normalization ....................................................................................... 67527.34. Integer value localization .......................................................................................... 67627.35. Integer value testing ................................................................................................. 67627.36. Converting numerals from Eastern Arabic scripts to European/Latin scripts ........................ 67727.37. Converting numerals from Latin script to Eastern Arabic script ........................................ 67727.38. Getting 4 letter CLDR script code using a native-language name of the script ..................... 67727.39. Normalizing a date .................................................................................................. 68027.40. Normalizing a date by locale ..................................................................................... 68127.41. Normalizing a date with time ..................................................................................... 68127.42. Normalizing a userdefined date .................................................................................. 68127.43. Automatic correction of input dates ............................................................................ 68227.44. Date testing ............................................................................................................ 68327.45. Normalize an unknown time ...................................................................................... 68327.46. Testing a time ......................................................................................................... 68428.1. Logging with Zend_Controller_Front ................................................................ 70128.2. Logging without Zend_Controller_Front ............................................................ 70129.1. Simple E-Mail with Zend_Mail ................................................................................... 707

xxxiii

Programmer's Reference Guide

Page 34: stacks on stacks on stacks

29.2. Passing additional parameters to the Zend_Mail_Transport_Sendmail transport .................... 70829.3. Sending E-Mail via SMTP .......................................................................................... 70829.4. Sending Multiple Mails per SMTP Connection ............................................................... 70929.5. Manually controlling the transport connection ................................................................ 71029.6. Using Different Transports ......................................................................................... 71029.7. Sending HTML E-Mail .............................................................................................. 71129.8. E-Mail Messages with Attachments .............................................................................. 71129.9. Changing the MIME Boundary .................................................................................... 71329.10. Adding E-Mail Message Headers ............................................................................... 71329.11. Enabling authentication within Zend_Mail_Transport_Smtp ............................................ 71429.12. Enabling a secure connection within Zend_Mail_Transport_Smtp .................................... 71430.1. Converting measurements ........................................................................................... 72730.2. The meter measurement ........................................................................................... 72730.3. Creation using integer and floating values ...................................................................... 72830.4. Creation using strings ................................................................................................ 72830.5. Arbitrary text input containing measurements ................................................................. 72930.6. Localized string ........................................................................................................ 72930.7. Automatic output ...................................................................................................... 73030.8. Output a value .......................................................................................................... 73030.9. Outputting units ........................................................................................................ 73130.10. Convert ................................................................................................................. 73230.11. Adding units ........................................................................................................... 73230.12. Subtract ................................................................................................................. 73330.13. Different measurements ............................................................................................ 73330.14. Identical measurements ............................................................................................ 73330.15. Difference .............................................................................................................. 73430.16. Changing a value .................................................................................................... 73430.17. Changing the type ................................................................................................... 73531.1. Using Zend_Memory component ................................................................................. 73933.1. The Simple OpenID Login form .................................................................................. 75233.2. The Authentication Request Handler ............................................................................. 75233.3. The Authentication Response Verifier ........................................................................... 75333.4. The Complete OpenID Login Script ............................................................................. 75433.5. Authentication Request for Specified Realm .................................................................. 75533.6. Immediate Check without Interaction ........................................................................... 75533.7. Databse Storage ........................................................................................................ 75633.8. Sending Requests with a Simple Registration Extension ................................................... 76033.9. Verifying Responses with a Simple Registration Extension ............................................... 76033.10. Zend_Auth Adapter for OpenID ................................................................................. 76233.11. The Identity ........................................................................................................... 76433.12. Simple Identity Provider ........................................................................................... 76433.13. Simple Login Screen ................................................................................................ 76533.14. Simple Trust Screen ................................................................................................. 76633.15. All together ............................................................................................................ 76733.16. Identity with Profile ................................................................................................. 76833.17. Provider with SREG ................................................................................................ 76935.1. Create new or load existing PDF document. ................................................................... 77935.2. Requesting specified revision of the PDF document. ........................................................ 77935.3. Save PDF document. ................................................................................................. 78035.4. PDF document pages management. .............................................................................. 78135.5. Cloning existing page. ............................................................................................... 78135.6. Draw a string on the page ........................................................................................... 78535.7. Draw a UTF-8-encoded string on the page ..................................................................... 78635.8. Create a standard font ................................................................................................ 786

xxxiv

Programmer's Reference Guide

Page 35: stacks on stacks on stacks

35.9. Create a TrueType font ............................................................................................... 78735.10. Create a TrueType font, but do not embed it in the PDF document. ................................... 78835.11. Do not throw an exception for fonts that cannot be embedded. ......................................... 78835.12. Do not compress an embedded font. ............................................................................ 78835.13. Combining font embedding options. ........................................................................... 78935.14. Extracting fonts from a loaded document. .................................................................... 78935.15. Extracting font from a loaded document by specifying font name. .................................... 79035.16. Image drawing ........................................................................................................ 79135.17. Zend_Pdf module usage demo ................................................................................... 80236.1. Example of set() method ............................................................................................ 80536.2. Example of get() method ............................................................................................ 80536.3. Example of iterating over the registry ........................................................................... 80636.4. Example of constructing a registry ............................................................................... 80636.5. Example of initializing the static registry ....................................................................... 80636.6. Example of array access ............................................................................................. 80736.7. Example of object access ............................................................................................ 80736.8. Example of isRegistered() method ................................................................................ 80836.9. Example of isset() method .......................................................................................... 80836.10. Example of specifying the static registry's class name .................................................... 80836.11. Example of _unsetInstance() method ........................................................................... 80937.1. A basic REST request ................................................................................................ 81037.2. Response Status ........................................................................................................ 81137.3. Using Technorati's Rest Service ................................................................................... 81137.4. Example Technorati Response ..................................................................................... 81237.5. Setting Request Arguments ......................................................................................... 81337.6. Basic Zend_Rest_Server Usage - Classes ...................................................................... 81337.7. Basic Zend_Rest_Server Usage - Functions ................................................................... 81437.8. Returning Custom Status ............................................................................................ 81537.9. Return Custom XML ................................................................................................. 81638.1. Custom text Analyzer. ................................................................................................ 84940.1. isSpam() Usage ........................................................................................................ 87040.2. submitSpam() Usage ................................................................................................. 87040.3. submitHam() Usage .................................................................................................. 87140.4. Search Amazon Using the Traditional API ..................................................................... 87340.5. Search Amazon Using the Query API ........................................................................... 87340.6. Choosing an Amazon Web Service Country ................................................................... 87340.7. Looking up a Specific Amazon Item by ASIN ................................................................ 87440.8. Performing Amazon Item Searches ............................................................................... 87440.9. Using the ResponseGroup Option ............................................................................ 87440.10. Search Amazon Using the Alternative Query API .......................................................... 87540.11. Retrieving User Profile Information ............................................................................ 88240.12. Retrieving a User's Weekly Artist Chart ....................................................................... 88340.13. Retrieving Related Artists ......................................................................................... 88440.14. Get all posts ........................................................................................................... 88540.15. Accessing post lists .................................................................................................. 88740.16. Filtering a Post List with Specific Tags ........................................................................ 88740.17. Filtering a Post List by URL ...................................................................................... 88840.18. Post editing ............................................................................................................ 88840.19. Method call chaining ............................................................................................... 88840.20. Deleting posts ......................................................................................................... 88940.21. Adding a post ......................................................................................................... 88940.22. Tags ...................................................................................................................... 89040.23. Bundles ................................................................................................................. 89040.24. Retrieving public data .............................................................................................. 891

xxxv

Programmer's Reference Guide

Page 36: stacks on stacks on stacks

40.25. Changing the HTTP client of Zend_Rest_Client .................................................... 89140.26. Configuring your HTTP client to keep connections alive ................................................. 89240.27. Simple Flickr Photo Search ....................................................................................... 89240.28. Finding a Flickr User's Public Photos by E-Mail Address ................................................ 89340.29. Retrieving a Group's Pool Photos by Group ID ............................................................. 89340.30. Retrieving Flickr Image Details ................................................................................. 89440.31. Querying Links ....................................................................................................... 90240.32. Modifying Links ..................................................................................................... 90340.33. Working With Tags .................................................................................................. 90440.34. Working With Notes ................................................................................................ 90540.35. Retrieving Watchlists ............................................................................................... 90640.36. Sending your first query ........................................................................................... 92140.37. Refining your query ................................................................................................. 92240.38. Sending multiple queries with the same Zend_Service_Technorati instance ............ 92240.39. Consuming a result set object .................................................................................... 92340.40. Seeking a specific result set object .............................................................................. 92340.41. Consuming a standalone result object .......................................................................... 92440.42. Handling a Query Exception ..................................................................................... 92440.43. Getting API key daily usage information ...................................................................... 92540.44. Cosmos Query ........................................................................................................ 92640.45. Search Query ......................................................................................................... 92640.46. Tag Query .............................................................................................................. 92740.47. DailyCounts Query .................................................................................................. 92740.48. TopTags Query ....................................................................................................... 92840.49. BlogInfo Query ...................................................................................................... 92840.50. BlogPostTags Query ................................................................................................ 92940.51. GetInfo Query ........................................................................................................ 92940.52. Iterating result objects from a resultset collection .......................................................... 93140.53. Searching the Web with Yahoo! .................................................................................. 93440.54. Finding Images with Yahoo! ...................................................................................... 93440.55. Finding videos with Yahoo! ....................................................................................... 93440.56. Finding Local Businesses and Services with Yahoo! ....................................................... 93540.57. Searching Yahoo! News ............................................................................................ 93540.58. Searching Yahoo! Site Explorer Inbound Links ............................................................. 93540.59. Searching Yahoo! Site Explorer's PageData .................................................................. 93641.1. Counting Page Views ................................................................................................. 94341.2. New Way: Namespaces Avoid Collisions ....................................................................... 94441.3. Old Way: PHP Session Access ..................................................................................... 94441.4. Session Iteration ....................................................................................................... 94441.5. Accessing Session Data .............................................................................................. 94541.6. Starting the Global Session ......................................................................................... 94541.7. Locking Session Namespaces ...................................................................................... 94741.8. Expiration Examples ................................................................................................. 94741.9. Namespaced Sessions for Controllers with Automatic Expiration ....................................... 94841.10. Limiting Session Namespace Access to a Single Instance ................................................ 94941.11. Modifying Array Data with a Session Namespace .......................................................... 95041.12. Building Arrays Prior to Session Storage ..................................................................... 95041.13. Workaround: Reassign a Modified Array ..................................................................... 95041.14. Workaround: store array containing reference ............................................................... 95141.15. PHPUnit Testing Code Dependent on Zend_Session ...................................................... 95241.16. Using Zend_Config to Configure Zend_Session ............................................................ 95441.17. Session Fixation ...................................................................................................... 95841.18. Basic Setup ............................................................................................................ 961

xxxvi

Programmer's Reference Guide

Page 37: stacks on stacks on stacks

41.19. Using a Multi-Column Primary Key ........................................................................... 96243.1. Application Login TestCase example ............................................................................ 97943.2. Testing a UserController ............................................................................................ 98644.1. Using Zend_Text_Figlet ............................................................................................. 99246.1. Example of single-language PHP code ........................................................................ 100446.2. Example of multi-lingual PHP code ............................................................................ 100446.3. Example TMX file .................................................................................................. 100946.4. Example CSV file ................................................................................................... 101046.5. Example CSV file two ............................................................................................. 101046.6. Example INI file ..................................................................................................... 101146.7. Using translation options .......................................................................................... 101146.8. Handling languages with adapters .............................................................................. 101346.9. How automatically language detection works ............................................................... 101446.10. Scanning a directory structure for sources .................................................................. 101546.11. Directory scanning for languages .............................................................................. 101646.12. Filename scanning for languages .............................................................................. 101746.13. Checking if a text is translatable ............................................................................... 101946.14. Handling languages with adapters ............................................................................. 102047.1. Creating a New URI with Zend_Uri::factory() ................................................... 102147.2. Manipulating an Existing URI with Zend_Uri::factory() ...................................... 102147.3. URI Validation with Zend_Uri::check() .............................................................. 102247.4. Getting the Scheme from a Zend_Uri_* Object ......................................................... 102247.5. Getting the Entire URI from a Zend_Uri_* Object ..................................................... 102247.6. Validating a Zend_Uri_* Object ............................................................................. 102348.1. Creating a Simple Validation Class ............................................................................. 103548.2. Writing a Validation Class having Dependent Conditions ................................................ 103648.3. Validation with Independent Conditions, Multiple Reasons for Failure ............................... 103849.1. Example of compareVersion() method ......................................................................... 104050.1. Basic Usage of Action View Helper ............................................................................ 105850.2. Basic Usage of Partials ............................................................................................. 105950.3. Using PartialLoop to Render Iterable Models ............................................................... 106150.4. Rendering Partials in Other Modules ........................................................................... 106250.5. Basic Usage of Placeholders ...................................................................................... 106250.6. Using Placeholders to Aggregate Content ..................................................................... 106350.7. Using Placeholders to Capture Content ........................................................................ 106450.8. Doctype Helper Basic Usage ..................................................................................... 106650.9. Retrieving the Doctype ............................................................................................. 106650.10. HeadLink Helper Basic Usage ................................................................................. 106750.11. HeadMeta Helper Basic Usage ................................................................................. 106950.12. HeadScript Helper Basic Usage ................................................................................ 107150.13. Capturing Scripts Using the HeadScript Helper ........................................................... 107250.14. HeadStyle Helper Basic Usage ................................................................................. 107350.15. Capturing Style Declarations Using the HeadStyle Helper ............................................. 107450.16. HeadTitle Helper Basic Usage ................................................................................. 107550.17. Flash helper .......................................................................................................... 107650.18. Customizing the object by passing additional arguments ............................................... 107750.19. Registered instance ................................................................................................ 107950.20. Within the view ..................................................................................................... 107950.21. Direct usage ......................................................................................................... 107950.22. Single parameter ................................................................................................... 108050.23. List of parameters .................................................................................................. 108050.24. Array of parameters ............................................................................................... 108050.25. Change locale dynamically ...................................................................................... 1081

xxxvii

Programmer's Reference Guide

Page 38: stacks on stacks on stacks

50.26. Change locale statically .......................................................................................... 108150.27. Get the currently set locale ...................................................................................... 108152.1. XML-RPC Method Call ........................................................................................... 108652.2. XML-RPC Method Call with Parameters ..................................................................... 108752.3. Proxy the Default Namespace .................................................................................... 108952.4. Proxy Any Namespace ............................................................................................. 109052.5. Handling HTTP Errors ............................................................................................. 109052.6. Handling XML-RPC Faults ....................................................................................... 109152.7. Processing Request to Response ................................................................................. 1092

xxxviii

Programmer's Reference Guide

Page 39: stacks on stacks on stacks

Chapter 1. Introduction to ZendFrameworkOverview

Zend Framework (ZF) is an open source framework for developing web applications and services withPHP 5. ZF is implemented using 100% object-oriented code. The component structure of ZF is somewhatunique; each component is designed with few dependencies on other components. This loosely coupledarchitecture 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 powerfuland extensible web application framework when combined. ZF offers a robust and performant MVC im-plementation, a database abstraction that is simple to use, and a forms component that implements HTMLform rendering, validation, and filtering so that developers can consolidate all of these operations usingone easy-to-use, object oriented interface. Other components, such as Zend_Auth and Zend_Acl, provideuser authentication and authorization against all common credential stores. Still others implement clientlibraries to simply access to the most popular web services available. Whatever your application needsare, you're likely to find a Zend Framework component that can be used to dramatically reduce developmenttime with a thoroughly tested foundation.

The principal sponsor of the Zend Framework project is Zend Technologies [http://www.zend.com], butmany companies have contributed components or significant features to the framework. Companies suchas Google, Microsoft, and StrikeIron have partnered with Zend to provide interfaces to web services andother 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 ZFcommunity. Community members, including contributors, make themselves available on mailing lists[http://framework.zend.com/archives], IRC channels [http://www.zftalk.com], and other forums. Whateverquestion you have about ZF, the community is always available to address it.

InstallationZend Framework requires PHP 5.1.4 or higher, although Zend strongly recommended 5.2.3 or higher asthere were some critical security and performance enhancements introduces between these two versions.You can find more details in the requirements appendix.

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 alsowant to move the library folder to another- possibly shared- location on your filesystem.

• Download the latest stable release. [http://framework.zend.com/download] This version, available inboth .zip and .tar.gz formats, is a good choice for those who are new to Zend Framework.

• Download the latest nightly snapshot. [http://framework.zend.com/download/snapshot] For those whowould brave the cutting edge, the nightly snapshots represent the latest progress of Zend Frameworkdevelopment. Snapshots are bundled with documentation either in English only or in all available lan-guages. If you anticipate working with the latest Zend Framework developments, consider using aSubversion (SVN) client.

1

Page 40: stacks on stacks on stacks

• Using a Subversion [http://subversion.tigris.org] (SVN) client. Zend Framework is open source software,and the Subversion repository used for its development is publicly available. Consider using SVN toget the Zend Framework if you already use SVN for your application development, want to contributeback to the framework, or need to upgrade your framework version more often than releases occur.

Exporting [http://svnbook.red-bean.com/nightly/en/svn.ref.svn.c.export.html] is useful if you want toget a particular framework revision without the .svn directories as created in a working copy.

Checking out a working copy [http://svnbook.red-bean.com/nightly/en/svn.ref.svn.c.checkout.html] isgood when you might contribute to Zend Framework, and a working copy can be updated any time withsvn update [http://svnbook.red-bean.com/nightly/en/svn.ref.svn.c.update.html].

An externals definition [http://svnbook.red-bean.com/nightly/en/svn.advanced.externals.html] is highlyconvenient for developers already using SVN to manage their application working copies.

The URL for the trunk of the Zend Framework SVN repository is: http://framework.zend.com/svn/frame-work/standard/trunk

Once you have a copy of the Zend Framework available, your application needs to be able to access theframework classes. Though there are several ways to achieve this[http://www.php.net/manual/en/configuration.changes.php], your PHP include_path[http://www.php.net/manual/en/ini.core.php#ini.include-path] needs to contain the path to the ZendFramework library.

Zend provides a QuickStart [http://framework.zend.com/docs/quickstart] to get you up and running asquickly as possible. This is an excellent way to begin learning about the framework with an emphasis onreal world examples that you can built upon.

Since Zend Framework components are loosely coupled, you may use a somewhat unique combination ofthem in your own applications. The following chapters provide a comprehensive reference to ZendFramework on a component-by- component basis.

2

Introduction to Zend Framework