Tài liệu ZendFramework 2 3 1

1.7K 2.6K 1
Tài liệu ZendFramework 2 3 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Tài liệu tham khảo lập trình Zend Framework 2.3.1

Zend Framework 2 Documentation Release 2.3.1 Zend Technologies Ltd. April 15, 2014 Contents 1 Overview 1 2 Installation 3 3 Getting Started with Zend Framework 2 5 3.1 Some assumptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3.2 The tutorial application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 4 Getting started: A skeleton application 7 4.1 Using the Apache Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.2 Using the Built-in PHP CLI Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.3 Error reporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 5 Routing and controllers 11 6 Create the controller 13 6.1 Initialise the view scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7 Database and models 15 7.1 The database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 7.2 The model files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 7.3 Using ServiceManager to configure the table gateway and inject into the AlbumTable . . . . . . . . . 17 7.4 Back to the controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 7.5 Listing albums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 8 Styling and Translations 23 9 Forms and actions 25 9.1 Adding new albums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 9.2 Editing an album . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 9.3 Deleting an album . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.4 Ensuring that the home page displays the list of albums . . . . . . . . . . . . . . . . . . . . . . . . . 34 10 Conclusion 35 i 11 Getting Started with Zend Framework 2 37 11.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 11.2 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 12 A quick tour of the skeleton application 43 12.1 The dispatch cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 13 The MyTaskList application 47 13.1 The Checklist module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 13.2 The Module class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 14 The application’s pages 51 14.1 Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 14.2 The TaskController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 14.3 The model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 14.4 Using Service Manager to configure the database credentials and inject into the controller . . . . . . 56 15 Listing tasks 59 15.1 Redirect the home page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 16 Styling 63 17 Adding new tasks 65 18 Editing a task 71 19 Deleting a task 75 20 Application Diagnostics 77 21 Step-by-step debugging 79 22 Conclusion 81 23 Zend Framework Tool (ZFTool) 83 23.1 Installation using Composer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 23.2 Manual installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 23.3 Without installation, using the PHAR file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 23.4 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 24 Learning Dependency Injection 87 24.1 Very brief introduction to Di. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 24.2 Simplest usage case (2 classes, one consumes the other) . . . . . . . . . . . . . . . . . . . . . . . . 87 24.3 Simplest Usage Case Without Type-hints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 24.4 Simplest usage case with Compiled Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 24.5 Creating a precompiled definition for others to use . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 24.6 Using Multiple Definitions From Multiple Sources . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 24.7 Generating Service Locators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 25 Unit Testing a Zend Framework 2 application 97 25.1 Setting up the tests directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 25.2 Bootstrapping your tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 25.3 Your first controller test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 25.4 A failing test case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 25.5 Configuring the service manager for the tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 25.6 Testing actions with POST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 ii 25.7 Testing model entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 25.8 Testing model tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 25.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 26 Using the EventManager 111 26.1 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 26.2 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 26.3 Shared managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 27 Wildcards 115 28 Listener aggregates 117 28.1 Introspecting results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 28.2 Short-circuiting listener execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 28.3 Keeping it in order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 28.4 Custom event objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 28.5 Putting it together: Implementing a simple caching system . . . . . . . . . . . . . . . . . . . . . . . 121 28.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 29 Advanced Configuration Tricks 125 29.1 System configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 29.2 Module Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 29.3 Configuration mapping table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 29.4 Configuration Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 29.5 Manipulating merged configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 29.6 Configuration merging workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 30 Using Zend\Navigation in your Album Module 133 30.1 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 30.2 Setting Up Zend\Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 30.3 Configuring our Site Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 30.4 Adding the Menu View Helper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 30.5 Adding Breadcrumbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 31 Using Zend\Paginator in your Album Module 137 31.1 Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 31.2 Modifying the AlbumTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 31.3 Modifying the AlbumController . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 31.4 Updating the View Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 31.5 Creating the Pagination Control Partial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 32 Using the PaginationControl View Helper 145 33 Setting up a database adapter 147 33.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 33.2 Basic setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 33.3 Setting a static adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 34 Migration from Zend Framework 1 149 35 Namespacing Old Classes 151 35.1 Namespacing a ZF1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 35.2 HOWTO Namespace Your Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 36 Running Zend Framework 2 and Zend Framework 1 in parallel 155 36.1 Use ZF2 in a ZF1 project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 iii 36.2 Use ZF1 in a ZF2 project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 36.3 Run ZF1 and ZF2 together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 37 Introduction to Zend\Authentication 159 37.1 Adapters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 37.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 37.3 Identity Persistence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 37.4 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 38 Database Table Authentication 167 38.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 38.2 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 38.3 Advanced Usage: Persisting a DbTable Result Object . . . . . . . . . . . . . . . . . . . . . . . . . . 170 39 Digest Authentication 173 39.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 39.2 Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 39.3 Identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 40 HTTP Authentication Adapter 175 40.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 40.2 Design Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 40.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 40.4 Resolvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 40.5 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 41 LDAP Authentication 179 41.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 41.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 41.3 The API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 41.4 Server Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 41.5 Collecting Debugging Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 41.6 Common Options for Specific Servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 42 Authentication Validator 187 42.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 42.2 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 43 Introduction to Zend\Barcode 189 44 Barcode creation using Zend\Barcode\Barcode class 191 44.1 Using Zend\Barcode\Barcode::factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 44.2 Drawing a barcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 44.3 Rendering a barcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 45 Zend\Barcode\Barcode Objects 195 45.1 Common Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 45.2 Common Additional Getters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 45.3 Description of shipped barcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 46 Zend\Barcode Renderers 205 46.1 Common Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 46.2 Zend\Barcode\Renderer\Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 46.3 Zend\Barcode\Renderer\Pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 iv 47 Zend\Cache\Storage\Adapter 207 47.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 47.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 47.3 Basic Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 47.4 The StorageInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 47.5 The AvailableSpaceCapableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 47.6 The TotalSpaceCapableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 47.7 The ClearByNamespaceInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 47.8 The ClearByPrefixInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 47.9 The ClearExpiredInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 47.10 The FlushableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 47.11 The IterableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 47.12 The OptimizableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 47.13 The TaggableInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 47.14 The Apc Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 47.15 The Dba Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 47.16 The Filesystem Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 47.17 The Memcached Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 47.18 The Memory Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 47.19 The WinCache Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 47.20 The XCache Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 47.21 The ZendServerDisk Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 47.22 The ZendServerShm Adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 47.23 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 48 Zend\Cache\Storage\Capabilities 223 48.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 48.2 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 48.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 49 Zend\Cache\Storage\Plugin 227 49.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 49.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227 49.3 The ClearExpiredByFactor Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 49.4 The ExceptionHandler Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 49.5 The IgnoreUserAbort Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 49.6 The OptimizeByFactor Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 49.7 The Serializer Plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 49.8 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 49.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 50 Zend\Cache\Pattern 231 50.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 50.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 50.3 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 51 Zend\Cache\Pattern\CallbackCache 233 51.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 51.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 51.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 51.4 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 51.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 52 Zend\Cache\Pattern\ClassCache 235 52.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 v 52.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 52.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 52.4 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 52.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 53 Zend\Cache\Pattern\ObjectCache 239 53.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 53.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 53.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 53.4 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 53.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 54 Zend\Cache\Pattern\OutputCache 243 54.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 54.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 54.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 54.4 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 54.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 55 Zend\Cache\Pattern\CaptureCache 245 55.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 55.2 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 55.3 Configuration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 55.4 Available Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246 55.5 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 56 Introduction to Zend\Captcha 249 56.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 57 Captcha Operation 251 57.1 The AdapterInterface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 57.2 Basic Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 58 CAPTCHA Adapters 253 58.1 Zend\Captcha\AbstractWord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 58.2 Zend\Captcha\Dumb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 58.3 Zend\Captcha\Figlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 58.4 Zend\Captcha\Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 58.5 Zend\Captcha\ReCaptcha . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255 59 Introduction 257 59.1 Theory of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 60 ZendCodeGenerator Reference 261 60.1 Abstract Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 60.2 Concrete CodeGenerator Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262 61 ZendCodeGenerator Examples 269 62 Introduction to Zend\Config 277 62.1 Using Zend\Config\Config with a Reader Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 62.2 Using Zend\Config\Config with a PHP Configuration File . . . . . . . . . . . . . . . . . . . . . . . 278 63 Theory of Operation 279 vi 64 Zend\Config\Reader 281 64.1 Zend\Config\Reader\Ini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 64.2 Zend\Config\Reader\Xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 64.3 Zend\Config\Reader\Json . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 64.4 Zend\Config\Reader\Yaml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 65 Zend\Config\Writer 287 65.1 Zend\Config\Writer\Ini . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 65.2 Zend\Config\Writer\Xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288 65.3 Zend\Config\Writer\PhpArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 65.4 Zend\Config\Writer\Json . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 65.5 Zend\Config\Writer\Yaml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 66 Zend\Config\Processor 293 66.1 Zend\Config\Processor\Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 66.2 Zend\Config\Processor\Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 66.3 Zend\Config\Processor\Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 66.4 Zend\Config\Processor\Token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 66.5 Zend\Config\Processor\Translator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 67 The Factory 297 67.1 Loading configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 67.2 Storing configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 68 Introduction to Zend\Console 299 68.1 Writing console routes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 68.2 Handling console requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 68.3 Adding console usage info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 69 Console routes and routing 305 69.1 Router configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 69.2 Basic route . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 69.3 Catchall route . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 69.4 Console routes cheat-sheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 70 Console-aware modules 313 70.1 Application banner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 70.2 Basic usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 70.3 Best practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 71 Console-aware action controllers 323 71.1 Handling console requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 71.2 Sending output to console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 71.3 Are we in a console? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 71.4 Reading values from console parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 72 Console adapters 331 72.1 Retrieving console adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 72.2 Using console adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 73 Console prompts 335 73.1 Confirm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 73.2 Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 73.3 Char . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 73.4 Select . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338 vii 74 ZendConsoleGetopt 341 74.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 75 Declaring Getopt Rules 343 75.1 Declaring Options with the Short Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 75.2 Declaring Options with the Long Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 76 Fetching Options and Arguments 345 76.1 Handling Getopt Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 76.2 Fetching Options by Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 76.3 Reporting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 76.4 Fetching Non-option Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 77 Configuring Zend\Console\Getopt 349 77.1 Adding Option Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 77.2 Adding Help Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 77.3 Adding Option Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 77.4 Adding Argument Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 77.5 Adding Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 78 Introduction to Zend\Crypt 353 79 Encrypt/decrypt using block ciphers 355 80 Key derivation function 357 80.1 Pbkdf2 adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 80.2 SaltedS2k adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 80.3 Scrypt adapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 81 Password 361 81.1 Bcrypt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 81.2 Apache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 82 Public key cryptography 365 82.1 Diffie-Hellman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 82.2 RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 83 Zend\Db\Adapter 371 83.1 Creating an Adapter - Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 83.2 Creating an Adapter Using Dependency Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 83.3 Query Preparation Through Zend\Db\Adapter\Adapter::query() . . . . . . . . . . . . . . . . . . . . 372 83.4 Query Execution Through Zend\Db\Adapter\Adapter::query() . . . . . . . . . . . . . . . . . . . . . 373 83.5 Creating Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 83.6 Using the Driver Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 83.7 Using The Platform Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 83.8 Using The Parameter Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 83.9 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 84 Zend\Db\ResultSet 379 84.1 Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 84.2 Zend\Db\ResultSet\ResultSet and Zend\Db\ResultSet\AbstractResultSet . . . . . . . . . . . . . . . . 380 84.3 Zend\Db\ResultSet\HydratingResultSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 85 Zend\Db\Sql 383 85.1 Zend\Db\Sql\Sql (Quickstart) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 85.2 Zend\Db\Sql’s Select, Insert, Update and Delete . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 viii [...]... 23 4Introduction to Zend\Server 11 11 111 1 11 11 111 1 11 12 11 12 11 13 11 15 23 5Zend\Server\Reflection 11 17 23 5 .1 Introduction 11 17 23 5 .2 Usage 11 17 23 6Zend\ServiceManager 11 19 23 7Zend\ServiceManager Quick Start 1 1 23 23 7 .1 Using Configuration 1 1 23 23 7 .2 Modules... 5 21 5 21 522 5 23 5 23 526 527 5 32 533 533 539 5 41 xi 12 1 .12 Null 12 1 .13 NumberFormat 12 1 .14 PregReplace 12 1 .15 RealPath 12 1 .16 StringToLower 12 1 .17 StringToUpper 12 1 .18 StringTrim 12 1 .19 StripNewLines 12 1 .20 StripTags 12 1 . 21 UriNormalize ... 12 6 1 12 6 1 12 6 1 12 6 2 12 6 2 12 6 2 12 6 2 12 6 3 12 6 4 12 6 4 28 0File Validation Classes 28 0 .1 Crc 32 28 0 .2 ExcludeExtension 28 0 .3 ExcludeMimeType 28 0.4 Exists 28 0.5 Extension 28 0.6 Hash 28 0.7 ImageSize 28 0.8 IsCompressed 28 0.9 IsImage 28 0 .10 Md5 28 0 .11 MimeType 28 0 .12 NotExists 28 0 .13 Sha1 28 0 .14 Size 28 0 .15 UploadFile 28 0 .16 WordCount... 13 1 9 13 1 9 1 32 0 1 32 0 1 32 0 1 32 1 1 32 2 1 32 3 1 32 4 1 32 4 1 32 5 1 32 5 1 32 7 1 32 7 1 32 8 1 32 9 1 32 9 29 8Validator Chains 13 3 1 29 8 .1 Overview... 13 7 7 13 7 7 13 7 7 13 7 7 13 7 8 13 7 8 13 7 9 31 1Gravatar Helper 13 8 1 31 1. 1 Introduction 13 8 1 31 1 .2 Basic Usage 13 8 1 31 1 .3 Custom Settings 13 8 1 31 2View Helper - HeadLink 13 8 5 3 12 . 1 Introduction 13 8 5 3 12 . 2 Basic... 1 13 3 1 13 3 1 13 3 1 13 3 1 13 5 24 0Session Config 1 13 7 24 0 .1 Standard Config 1 13 7 24 0 .2 Session Config 1 13 8 24 0 .3 Custom Configuration 1 13 9 xxiii 24 1Session Container 11 41 24 1. 1 Basic Usage 11 41 24 1 .2 Setting the Default... 13 1 1 13 1 1 13 1 1 13 12 13 12 13 12 295Step 13 1 3 29 5 .1 Supported options for Zend\Validator\Step 13 1 3 29 5 .2 Basic usage 13 1 3 xxviii 29 5 .3 Using floating-point values 13 1 3 29 6StringLength 29 6 .1 Supported options for Zend\Validator\StringLength 29 6 .2 Default behaviour for... 5 41 5 43 544 544 545 546 547 547 548 549 12 2 Word Filters 12 2 .1 CamelCaseToDash 12 2 .2 CamelCaseToSeparator 12 2 .3 CamelCaseToUnderscore 12 2 .4 DashToCamelCase 12 2 .5 DashToSeparator 12 2 .6 DashToUnderscore 12 2 .7 SeparatorToCamelCase 12 2 .8 SeparatorToDash 12 2 .9 SeparatorToSeparator 12 2 .10 UnderscoreToCamelCase 12 2 .11 UnderscoreToSeparator 12 2 .12 UnderscoreToDash ... 517 517 517 518 518 12 1 Standard Filter Classes 12 1 .1 Alnum 12 1 .2 Alpha 12 1 .3 BaseName 12 1 .4 Boolean 12 1 .5 Callback 12 1 .6 Compress and Decompress 12 1 .7 Digits 12 1 .8 Dir 12 1 .9 Encrypt and Decrypt 12 1 .10 HtmlEntities 12 1 .11 Int ... 10 13 10 13 10 19 1 020 1 0 21 1 0 23 1 0 23 21 4View Helpers 21 4 .1 Introduction 21 4 .2 Translation of labels and titles 21 4 .3 Integration with ACL 21 4.4 Navigation setup used in examples 1 027 1 027 1 028 1 029 1 029 21 5View Helper - Breadcrumbs 21 5.1 . . . . . . . . . . . . . 33 2 73 Console prompts 33 5 73. 1 Confirm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 6 73. 2 Line . . . . . . . . . . . . . . . . . . . . . . . . 633 133 .2 Element Base Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633 133 .3 Standard Elements . . . . . . . . . . . . . . . . . 629 132 .4 The specific case of initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631 133 Form Elements 633 133 .1 Introduction . . . .

Ngày đăng: 17/05/2014, 17:16

Từ khóa liên quan

Mục lục

  • Overview

  • Installation

  • Getting Started with Zend Framework 2

    • Some assumptions

    • The tutorial application

    • Getting started: A skeleton application

      • Using the Apache Web Server

      • Using the Built-in PHP CLI Server

      • Error reporting

      • Routing and controllers

      • Create the controller

        • Initialise the view scripts

        • Database and models

          • The database

          • The model files

          • Using ServiceManager to configure the table gateway and inject into the AlbumTable

          • Back to the controller

          • Listing albums

          • Styling and Translations

          • Forms and actions

            • Adding new albums

            • Editing an album

            • Deleting an album

            • Ensuring that the home page displays the list of albums

            • Conclusion

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan