Contents
preface xvii
acknowledgments xix
about this book xxi
about the cover illustration xxvi
Part 1 The essentials 1
Introducing Zend Framework 3
Introducing structure to PHP websites 4
Why use Zend Framework? 5
Everything is in the box 6, Modern design 6, Easy to learn 6, Full documentation 7, Simple development 8, Rapid development 8, Structured code is easy to maintain 8
What is Zend Framework? 9
Where did it come from? 9, What’s in it? 9
Zend Framework design philosophy 15
High-quality components 15, Pragmatism and Flexibility 15, Clean IP 16, Support from Zend Technologies 16
Alternative PHP frameworks 16
Summary 17
Hello Zend Framework! 18
The Model-View-Controller design pattern 19
The model 20, The view 20, The controller 20
The anatomy of a Zend Framework application 21
The application directory 21, The library directory 21, The tests directory 21, The public directory 22
Defining Ajax 88, Using Ajax in web applications 89
A simple Ajax example 91
Using Ajax client libraries 94
Using Ajax with Zend Framework 95
The controller 96, The view 97
Integrating into a Zend Framework application 98
The Place controller 99, Adding review rating HTML to the view script 101, Adding JavaScript to the view scripts 102, The server code 104
Summary 106
Managing the database 107
Database abstraction with Zend_Db_Adapter 108
Creating a Zend_Db_Adapter 108, Querying the database 109
Inserting, updating, and deleting 110, Handling database-specific differences 111
Table abstraction with Zend_Db_Table 112
What is the Table Data Gateway pattern? 112, Using Zend_Db_Table 113, Inserting and updating with Zend_Db_Table 114, Deleting records with Zend_Db_Table 116
Using Zend_Db_Table as a model 116
Testing the model 118, Table relationships with Zend_Db_Table 123
Summary 127
User authentication and access control 128
Introducing authentication and access control 129
What is authentication? 129, What is access control? 129
Implementing authentication 130
Introducing Zend_Auth 130, Logging in using HTTP authentication 131
Using Zend_Auth in a real application 133
Logging in 133, A view helper welcome message 137, Logging out 138
Implementing access control 139
Introducing Zend_Acl 139, Configuring a Zend_Acl object 141, Checking the Zend_Acl object 142
Summary 146
Forms 147
Introducing Zend_Form 148
Integrated data filters and validators 148, Integrated error handling 150, Decorators to simplify markup 151, Plug-in loaders for customization 152, Internationalization 152, Subforms and display groups 152
Building a login form 153
Setting up paths 153, Our form view script 153, Updating the AuthController controller action 15, The basic login form class 155
Filtering and validation 156
Basic filtering and validation 156, Custom error messages 158, Internationalizing the form 159, Adding a custom validator 160
Decorating our login form 162
Zend_Form default decorators 162, Setting our own decorators 162
Summary 166
Searching 167
Benefits of search 168
Key usability issue for users 168, Ranking results is important 168
Introducing Zend_Search_Lucene 168
Creating a separate search index for your website 169, Powerful queries 171, Best practices 175
Adding search to Places 176
Updating the index as new content is added 176, Creating the search form and displaying the results 185
Summary 188
Email 189
The basics of email 190
Email simplified 190, Dissecting an email address 191
Introducing Zend_Mail 191
Creating emails with Zend_Mail 191, Sending emails with Zend_Mail 193
Building a support tracker for Places 195
Designing the application 195, Integrating Zend_Mail into the application 199, Adding headers to the support email 200, Adding attachments to the support email 202, Formatting the email 203
Reading email 205
Collecting and storing email 205, Reading email with our application 206
Summary 210
Deployment 211
Setting up the server 211
Designing for different environments 212, Using virtual hosts for development 214
Version control with Subversion 216
Creating the Subversion repository 217, Checking out code from the repository 218, Committing changes to the repository 218, Updating a local working copy 219, Dealing with conflicts 220, Getting a clean copy from the repository 222, Using branches 222, Externals 223
Functional testing 223
Functional testing with Selenium IDE 224, Automating Selenium IDE tests 226, Functional testing with Zend_Http_Client 227
Scripting the deployment 229
Summary 229
Part 3 More power to your application 231
Talking with other applications 233
Integrating applications 234
Exchanging structured data 234, Producing and consuming structured data 235, How web services work 236, Why we need web services 237
Producing and consuming feeds with Zend_Feed 237
Producing a feed 237, Consuming a feed 239
Making RPCs with Zend_XmlRpc 240
Using Zend_XmlRpc_Server 241, Using Zend_XmlRpc_Client 248
Using REST web services with Zend_Rest 250
What is REST? 250, Using Zend_Rest_Client 251, Using Zend_Rest_Server 254