1. Trang chủ
  2. » Công Nghệ Thông Tin

Manning zend framework in action dec 2008 ISBN 1933988320 pdf

434 151 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 434
Dung lượng 5,22 MB

Nội dung

Zend Framework in Action Zend Framework in Action ROB ALLEN NICK LO STEVEN BROWN MANNING Greenwich (74° w long.) For online information and ordering of this and other Manning books, please visit www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact: Special Sales Department Manning Publications Co Sound View Court 3B Fax: (609) 877-8256 Greenwick, CT 06830 Email: orders@manning.com ©2009 by Manning Publications Co All rights reserved No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed elemental chlorine-free Manning Publications Co Sound View Court 3B Greenwich, CT 06830 Copyeditor: Andy Carroll Typesetter: Tony Roberts Cover designer: Leslie Haimes ISBN: 1933988320 Printed in the United States of America 10 – VHG – 13 12 11 10 09 08 07 To Georgina, Jon, and Ben, for the love and support that you give me —R.A To the Cookie Fairy and her two little helpers, Cory and Cass, for the nourishment you give me —N.L To Grandma, for believing in me —S.B brief contents PART THE ESSENTIALS 1 ■ Introducing Zend Framework ■ Hello Zend Framework! 18 PART A CORE APPLICATION 41 ■ Building a website with Zend Framework 43 ■ Managing the view ■ Ajax ■ Managing the database ■ User authentication and access control 128 ■ Forms ■ Searching 167 10 ■ Email 189 11 ■ Deployment 211 64 87 147 vii 107 viii BRIEF CONTENTS PART MORE POWER TO YOUR APPLICATION 231 12 ■ Talking with other applications 13 ■ Mashups with public web services 14 ■ Caching: making it faster 280 15 ■ Internationalization and localization 16 ■ Creating PDFs 316 233 257 299 contents preface xvii acknowledgments xix about this book xxi about the cover illustration PART 1 xxvi THE ESSENTIALS .1 Introducing Zend Framework 1.1 1.2 Introducing structure to PHP websites Why use Zend Framework? Everything is in the box Modern design Easy to learn Full documentation Simple development Rapid development Structured code is easy to maintain ■ ■ ■ ■ ■ 1.3 What is Zend Framework? Where did it come from? 1.4 9 ■ What’s in it? Zend Framework design philosophy 15 High-quality components 15 Pragmatism and Flexibility Clean IP 16 Support from Zend Technologies 16 ■ ■ ix 15 393 reusability review feedback system 99 review_feedback.js 102 ReviewController::feedbackAction() 104 rewind() 361 RewriteCond 24 RewriteRule 24 RFC 84, 240 RGB 324 role 12, 139 role-based access control See RBACL role-based ACL 139 ROOT_DIR 120, 309 rotation objects 332 page 332 route defaults 373–374 implementing new 307 object 373 regex 375 static 374 template 373 router 27, 369 rewrite 373 standard 373 routeShutdown() 31 routeStartup() 31 routing 19, 29, 373 implementing a new route 307 numeric keys 375 regex route 375 static route 374 Row Data Gateway design pattern 112, 366 rowset 238 RPC 235–236 key element 250 middleware 241 RSS feed 237 consuming 239 parsing 239 Ruby on Rails 154 Ruby on Rails See Rails runXmlRpc() 242 S salt 136 same-origin policy 226 saveIssue() 197 saveXml() 239 score 187 SDN 262 search adding to index 177, 179 available fields for display 187 benefits 168 Boolean operators 172 create a new index 185 designing the index 177 display results 186 field types 170 field types, when to use 170 full text search engine 169 indexing 170 modifiers 171 multiterm query 173 phrase query 174 processing results 185 programmatic query 173 query 171 query objects 173 query parser 171 querying the index 171 range query 175 ranking 168 re-indexing 184 relationship between index, documents and fields 168 score 187 slop 174 string queries 171 term 171 term query 173 tokenizing 170 wildcard 171 wildcard query 174 search engine Apache Lucene 14 SearchIndexer 181 addToIndex() 183 getDocument() 182 observeTableRow() 181 section inheritance 50 security 11, 246 email header injection 193 SQL injection 36, 109 SQL injection vulnerability 106 XSS 27, 33–34 Selenium 224 automating tests 226 editing tests 224 IDE 224 PHPUnit test case 226 RC 226 RC Server 227 saving tests 226 source view 225 test runner 226 self-documenting code 357 394 send() 238 separation of concerns serialize() 234, 287 serialized data 234 server 229 setup 211 setAction() 155 setBodyHtml() 203 setBodyText() 203 setControllerDirectory() 369 SetCredentialTreatment() 136 setDecorators() 164 setDefaultAdapter() 37 setDefaultTransport() 194 setElementDecorators() 164 setHttpEquiv() 83 setLayout() 67 setLineDashingPattern() 328 setlocale() 301 problems 313 setMessage() 158 setName() 83 setRequired() 157 setting a unique cache identifier 287 setup environment 212 server 211 setUp() 119 setView() 137 SGML 234 sha1 136 SHA1 algorithm 287 sha1() 287 SHAPE_DRAW_FILL 329 SHAPE_DRAW_FILL_AND_STROKE 329 SHAPE_DRAW_STROKE 329 Simple Mail Transfer Protocol See SMTP simplicity 15 Simpy 262 Singleton design pattern 24, 66, 130 site goals 44 specifications 44 skeleton structure 48 SlideShare 263 Smarty 10, 20 template library SMTP 194 SOAP 13, 235 software design pattern 19, 362 Solar 17 spam 251 filtering 251 spinner animation 102 create 103 SPL 50, 359 ArrayAccess 361 Countable 361 DirectoryIterator 360 iterators 359 SQL 55, 59, 105 injection 109 injection vulnerability 106 join 123 placeholder 109 query 109 SQL Server 11, 109 SQLite 11 staging environment 212 standard dispatcher 30 Standard Generalized Markup Language See SGML Standard PHP Library See SPL standard router 369 start() 289 static files 24 route 374 variable 363 Storage Delivery Network See SDN story 44 Strategy design pattern 366 StrikeIron 263 string type 340 StripTags filter 186 strtok() 324 structured HTML 89 text 234 Struts Subversion 216 branches 222 checkout 218 commit 218 copy 222 dealing with conflicts 220 directory structure 218 export 222 externals 222–223 propedit 223 resolved 221 status 219 update 219 working copy 218 Sun 65 Support readMail() 209 saveIssue() 197 395 Support_Table 195 svn 216 commit 221 export 222 import 217 mkdir 217 propedit 223 resolved 221 status 219, 221 update 219, 229 svnadmin 217 Sweat, Jason 366 Symfony 6, 17 T Table Data Gateway 10 design pattern 37, 54, 112, 366 tables linking 123 relationships 123 tab-separated values See TSV tags 217 tagSearch() 271 tasks scheduled 176 TBX 303 Technorati 263 templates 20 action 66 master 66 route 373 terms of service 273 test case 56 case class 61 data 60 section 51 suite 228 TestConfiguration 58 class 57 testing 56 automatic 51 automating functional tests 226 framework 56 functional 223 JavaScript 229 model 56, 118 quick and dirty 375 recording a Selenium test 224 Selenium 224 Zend_Http_Client 227 testInsert() 122 tests directory 61 testUpdate() 122 text structured 234 Text search field type 170 title separator 85 TitleCase 29 toArray() 80 tokenizing 170 toNumber() 302 translate() 310 translating idioms 301 languages 300 a view script 310 translation file 311 language 300 TrueType font 322 trunk 217 TSV 234 Two Step View design pattern 65 definition 65 type hinting 356 example 209 type juggling 339 TypeKey 129 U UI 45 accessibility 46 designing 45 features 46 images 46 menus 46 navigation 46 page layout 46 widgets 94 UnIndexed search field type 170 unique identifier 283, 287 setting 287 unit test 21 model 56 unit testing 45, 56 _setupDatabase() 120 AllTests.php 57 controller 61 controller setup 62 directory organization 57 model 118, 121 model initialization 119 organization 57 process 45 setUp() 57, 119 tearDown() 57 test case 56 396 unit testing (continued) testInsert() 122 testUpdate() 122 UnStored search field type 170 update in-place 98 update() 111, 114 updating a local working copy 219 url() 79, 312 view helper 134, 370 urlencode 79 URLs action 372 controller 371 creation of 79 generation 79 hyphens in 372 scheme 369 User 117 user interface See UI Users class testing 121 V valid() 361 validation 12, 132 variable 351 parsing in strings 341 placeholder 373 static 363 variable 340 version control 216 video 274 categories 275 playing 278 VideosController viewAction() 278 View view adding JavaScript 102 file 279 helper 20, 33 master template 66 script 20, 32 view helper 266 action() 78 amazonAds 266 baseUrl() 71 case-sensitivity 78 controller integration 78 directory 68 displayAddress() 100 displayDate() 77 doctype() 69, 82 getSearchResultUrl() 187 head* 70 headlink() 82 headMeta() 83 headScript() 83 headTitle() 84 HTML header 81 json 81 layout() 70 LoggedInUser 137 naming 266 partial() 70, 80 partialLoop() 81 setView() 137 translate() 310 url() 79, 312, 370 view script management 80 ViewRenderer 25, 66 ViewSetup 67 virtual hosting 214 virtual hosts 214 directories 216 IP-based 215 name based 215 VirtualHost 216 W W3C 233, 235 WAI 46, 88 web feed 239 request 20 server 215 Web Accessibility Initiative See WAI web services 234, 236 Amazon example 264 caching 267 Flickr example 270 license 271 need for 237 overview 13 public 258 terms of use 274 YouTube categories 275 YouTube example 274 Web Services Description Language See WSDL website See site Wiedner, Thomas 312 will 130 Windows 301 Ecto 243 setlocale() problems 313 397 Winer, Dave 235 WordPress 263 word-separator characters 371 wordwrap() 324 working copy 218 World Wide Web Consortium See W3C wrapText() 324 write_control 285 WSDL 233 X X_REQUESTED_WITH 98 XLIFF 303 XML 89, 234, 239 xml.phtml 97 encoded request 249 encoded RPCs 240 XMLHttpRequest 89, 96 XML-RPC 13, 235 client 236 creating interfaces 243 diagram 236 errors 249 method handler 243 namespace 243 request 241 server 236, 241 XMLRPC_TYPE_DATETIME 247 XmlTm 303 X-Priority 202 XSS 27, 33–34 Y Yahoo! 13, 264 Flickr photo data 13 Yahoo! Images 264 Yahoo! Local 264 Yahoo! News 264 Yahoo! User Interface See YUI Yahoo! Web Search 264 YAHOO.util.Connect 95 YouTube 13, 259 API 275 iterating over a playlist 275 list of videos 276 playing a video 278 playlist 275 YUI 94 Connect object 98 integration 95 library files 94 Z Zend Framework 17 build-tools directory 229 class categories 6, code quality 15 component list components overview core classes 11 defined design patterns 366 design philosophy 15 documentation easy to learn features history intellectual property 16 maintenance modern design MVC flowchart 10 naming convention 320 online manual rapid development requirement 212 simpler development simplicity 15 structure tutorials why use Zend Framework 1.5 148 Zend Technologies 9, 16 Zend_Acl 12, 139 add 140 allow() 141 configuration 141 deny() 141 privilege inheritence 141 Zend_Acl_Resource 140 Zend_Acl_Role 139, 142 addRole() 140 Zend_Auth 12, 130, 134 authenticate() 131 clearIdentity() 138 getIdentity() 138 hasIdentity() 138 HTTP authentication flowchart 131 Zend_Auth adapter 130–131 Zend_Auth_Adapter_DbTable 135–136 Zend_Auth_Adapter_Http 131 getIdentity() 132 Zend_Cache 14, 267, 282 caching a database query 284 CLEANING_MODE_ALL 298 CLEANING_MODE_MATCHING_TAG 298 CLEANING_MODE_OLD 298 398 example 269, 282 frontend 284 implementing 284 lifetime 284 web services integration 269 Zend_Cache _Frontend_Class_Backend_ZendPlatform 286 Zend_Cache backend classes 295 Zend_Cache_ Backend_MemcachedFrontend_Output 286 Zend_Cache_ Frontend_FunctionBackend_Apc 286 Zend_Cache_Backend_Apc 296 Zend_Cache_Backend_File 282, 295 cache_dir 284, 295 file_locking 295 file_name_prefix 296 hashed_directory_level 284, 295 hashed_directory_umask 295 options 295 read_control 295 read_control_type 295 Zend_Cache_Backend_Memcached 296 Zend_Cache_Backend_Sqlite 296 Zend_Cache_Backend_ZendPlatform 296 Zend_Cache_Core 282, 284, 286 clean() 298 remove() 298 Zend_Cache_Coreache_Backend_Sqlite 286 Zend_Cache_Frontend_Class 291 cacheByDefault 291 cachedEntity 291 cachedMethods 291 nonCachedMethods 291 usage 291 Zend_Cache_Frontend_File 286, 292 example usage 292 master_file 292 Zend_Cache_Frontend_Function 289 cacheByDefault 289 cachedFunctions 290 call() 290 example usage 290 nonCachedFunctions 290 options 289 static functions 291 Zend_Cache_Frontend_Output 289 start() 289 Zend_Cache_Frontend_Page 286, 293 debug_header 293 default_options 293 example usage 294 regexps 294 start() 293 Zend_Cache_Frontend_page regexps examples 294 Zend_Config 50, 266, 359 data access 50 database initialization 52 get() 359 hierarchical separator 50 loading 50 section inheritance 50 test section 51 Zend_Config_Ini 213 inheritance 213 Zend_Controller_Action 20, 29–30 _helper 75 init() 30 postDispatch() 30 preDispatch() 30 Zend_Controller_Action_ViewRenderer 25 Zend_Controller_Dispatcher_Standard 29 Zend_Controller_Front 20, 24, 28 addControllerDirectory() 369 addModuleDirectory() 369 dispatch() 24 getControllerDirectory() 371 getInstance() 363 registerPlugin() 371 renderExceptions() 31 setControllerDirectory() 369 Singleton implementation 362 Zend_Controller_Plugin_ActionStack 72 Zend_Controller_Request getParam() 310 Zend_Controller_Request_Http 28 getParam() 28 Zend_Controller_Response_Cli 30 Zend_Controller_Response_Http 30 Zend_Controller_Router_Rewrite 29, 373 Zend_Controller_Router_Route 308, 373 Zend_Controller_Router_Route_Regex 374 Zend_Controller_Router_Route_Static 374 Zend_Currency 13 Zend_Date 78, 302, 313, 330 add() 84 constants 314 get() 84, 313 Zend_Db 35 factory() 35, 52, 108 getConnection() 109 params config section 378 profiling 377 query() 109 quote() 36, 109 security 36 Zend_Db_Adapter 52, 105, 108 compared with Zend_Db_Table 115 399 creating 108 delete() 111 insert() 110 query() 105 quoteInto() 111 update() 111 Zend_Db_Adapter_Pdo_Mysql 52 Zend_Db_Expr 111 Zend_Db_Profiler 377 enabling via a config object 377 getLastQueryProfile() 378 getTotalElapsedSecs() 379 getTotalNumQueries() 379 Zend_Db_Profiler_Query 379 Zend_Db_Select 109 Zend_Db_Table 10, 20, 36, 112, 195 compared with Zend_Db_Adapter 115 delete() 116 fetchAll() 59, 201 insert() 114 integration 116 overriding save() 199 setDefaultAdapter() 37 update() 114 using 113 Zend_Db_Table relationships 123 Zend_Db_Table_Abstract 112 $_dependantTables 123 $_name 113 $_referenceMap 123, 126 $_rowClass 117 fetchAll() 114 fetchNew() 122 findManyToManyRowset() 125, 127 Zend_Db_Table_AbstractfindDependentRowset() 124 Zend_Db_Table_Row 112 save() 115 Zend_Db_Table_Row_Abstract 117, 181 _postDelete() 181 _postInsert() 181 _postUpdate() 181 Zend_Db_Table_Rowset 112 Zend_Db_Table_Rowset_Abstract 361 Zend_Db_Table_Select 114 Zend_Debug 375 dump() 23, 375 Zend_Feed 13, 237 Zend_Filter 11, 148 chaining 149 list of classes 148 Zend_Filter_Input 186 display error messages 186 Zend_Form 148, 155, 198 addElement() 155 advantages 148 clearDecorators() 164 custom error messages 158 custom validator 160 decorators 162 default decorators 162 filtering 156 init() 156 internationalization 159 populate() 155 rendering 153 setAction() 155 setDecorators() 164 setElementDecorators() 164 setTranslator() 159 standard decorators 151 validation 156 Zend_Form setTranslator() 159 Zend_Form_Element addFilter() 156 addValidator() 156 setRequired() 157 Zend_Gdata 258, 274 getVideoEntry() 278 Zend_Http_Client 227, 253 Zend_Json 13, 82 Zend_Layout 10, 66 integrating 67 setLayout() 67 startMvc() 66 Zend_Loader 50 loadClass() 23 Zend_Locale 13, 301 checkDateFormat() 303 getDate() 303 getLanguage() 301, 308 getRegion() 301 toNumber() 302 Zend_Log 376, 378 addFilter() 377 log() 376 shortcut function 376 writer class 377 writer object 376 Zend_Log_Filter_Priority 377 Zend_Log_Writer_Db 377 Zend_Log_Writer_Firebug 377 Zend_Log_Writer_Null 377 Zend_Log_Writer_Stream 377 Zend_Mail 14, 191 addAttachment() 202 addBCC() 201 addCC() 201 addHeader() 193, 201 adding recipients 201 400 createAttachment() 193 creating emails 191 example 192 integration with Places 199 Maildir format 206 Mbox format 206 opening a connection to mail storage 207 process 190 reading email 206 sending email 193 sending via SMTP 194 setBodyHtml() 203–204 setBodyText() 203–204 setDefaultTransport() 194 setting priority 201 using the view for rendering 204 Zend_Mail_Storage retrieving plain text content 207 Zend_Mail_Storage_Abstract 207 Zend_Mail_Storage_Imap 207 Zend_Mail_Storage_Maildir 207 Zend_Mail_Storage_Mbox 207 Zend_Mail_Storage_Pop3 207 Zend_Mail_Transport_Interface 14 Zend_Mail_Transport_Sendmail 190 Zend_Mail_Transport_Smtp advantages 195 Zend_Measure 13 Zend_Mime 192 Zend_PDF save graphics state 323, 329, 332 Zend_Pdf 14, 317, 320 $properties 318 clipCircle() 333 clipEllipse() 333 clipping mask 333 clipPolygon() 333 clipRectangle() 333 coordinate system 321 custom font 322 custom page size 318 default style 326 drawCircle() 331 drawEllipse() 331 drawImage() 333 drawLine() 327 drawPolygon() 328 drawRectangle() 328 drawText() 323 filling shapes 328 height of page 322 imageWithPath() 332 load() 317 newPage() 318 parse() 317 render() 319 restoreGS 323 rotate() 332 save() 319 saveGS 323 set page font 323 setFont() 323 setStyle() 326 shapes 326 width of page 322 Zend_Pdf_Font 322 Zend_Pdf_Color 325 Zend_Pdf_Color_Cmyk 325 Zend_Pdf_Color_GrayScale 325 Zend_Pdf_Color_Html 325 Zend_Pdf_Color_Rgb 325 Zend_Pdf_Page 317, 321 Zend_Pdf_Page::SIZE_A4 317 Zend_Pdf_Style 326 Zend_Registry 52, 266, 364 getInstance() 365 implementation 365 Zend_Rest 250–251 Zend_Rest_Client 251, 255 Zend_Rest_Client:restPost() 253 Zend_Rest_Client_Result 255 Zend_Rest_Server 254 Zend_Search_Lucence addDocument() 178 Zend_Search_Lucene 14, 168 best practices 175 Binary field type 170 Boolean operators 172 field types 170 find() 171, 186 Keyword field type 170 MaxBufferedDocs 176 optimize() 171 Text field type 170 UnIndexed field type 170 UnStored field type 170 updating a document 183 UTF-8 176 Zend_Search_lucene addDocument() 169 create() 169 Zend_Search_Lucene_Document 177 Zend_Search_Lucene_Index_Term 173 Zend_Search_Lucene_Search_Query 171 Zend_Search_Lucene_Search_Query_MultiTerm 173 Zend_Search_Lucene_Search_Query_Phrase 174 Zend_Search_Lucene_Search_Query_Range 175 Zend_Search_Lucene_Search_Query_Wildcard 174 401 Zend_Search_Lucene_Search_QueryHit 168 Zend_Search_Lucene_Search_QueryParser 171 Zend_Server_Reflection 247 Zend_Service 258 Zend_Service_Akismet 251, 260 Zend_Service_Amazon 260 Zend_Service_Amazon_Query 265–266 Zend_Service_Audioscrobbler 261 Zend_Service_Delicious 261 Zend_Service_Flickr 261, 271 tagSearch() 271 Zend_Service_Gdata 258 Zend_Service_Gravatar 262 Zend_Service_Nirvanix 262 Zend_Service_RememberTheMilk 262 Zend_Service_Simpy 262 Zend_Service_StrikeIron 263 Zend_Service_Technorati 263 cosmos() 264 Zend_Service_Yahoo 264 pageDataSearch() 264 Zend_Translate 13, 303, 310 _() 304 supported input formats 303 using gettext() format 304 Zend_Validate 12, 148–149 isValid() 150, 160 setMessage() 158 Zend_Validate_EmailAddress 192 Zend_Validate_StringLength 159 Zend_View 10, 20, 25, 32 assign() 26, 32 helper 33 render HTML email 203 script file 32 security 34 Zend_View_Helper 33 Zend_View_Helper_Escape 27 Zend_View_Helper_FormatCurrency 33 Zend_Xml_RpcServer type mapping 247 Zend_XmlRpc 240 Zend_XmlRpc_Client 13, 248 Zend_XmlRpc_Client:call() 249 Zend_XmlRpc_Server 241–242 DocBlocks 246 Zend_XmlRpc_Server_Cache 247–248 Zend_XmlRpc_Value 247 Zend_XmlRpc_Value:XMLRPC_TYPE_DATETIME 247 Zend’s Studio ZendFeed:findfeeds() 240 ZendFeed:import() 240 ZendFeed:importFile() 240 ZendFeed:importString() 240 ZendFeed:saveXml() 239 ZendFeed:send() 238 ZFiA_Person 351 281, 362 .. .Zend Framework in Action Zend Framework in Action ROB ALLEN NICK LO STEVEN BROWN MANNING Greenwich (74° w long.) For online information and ordering of this and other Manning books,... Using Zend_ Db_Table 113 Inserting and updating with Zend_ Db_Table 114 Deleting records with Zend_ Db_Table 116 ■ ■ ■ xii CONTENTS 6.3 Using Zend_ Db_Table as a model 116 Testing the model 118 Zend_ Db_Table... Implementing access control 137 139 Introducing Zend_ Acl 139 Configuring a Zend_ Acl object 141 Checking the Zend_ Acl object 142 ■ ■ 7.5 Forms 8.1 Summary 146 147 Introducing Zend_ Form 148 Integrated

Ngày đăng: 19/04/2019, 13:42