Zend Framework in Action
Rob Allen, Nick Lo, Steven Brown
  • December 2008
  • ISBN 9781933988320
  • 432 pages
  • printed in black & white

Compelling ... a great introduction to the Zend Framework.

Thomas Weidner, Zend Framework

Zend Framework in Action is a comprehensive tutorial that shows how to use Zend Framework to create web-based applications and web services.

This book takes you on an "over-the-shoulder" tour of the components of Zend Framework as you build a high quality, real-world web application. This book fully supports version 1.5 of Zend Framework and is organized around the techniques you'll use every day as a web developer-data handling, forms, authentication, and so forth. As you follow the running example, you'll learn to build interactive Ajax- driven features into your application without sacrificing nuts-and-bolts considerations like security and performance.

Reflecting the Zend Framework's own emphasis on thorough testing and best practices, the book further promotes the benefits of testing during development and before deployment. This book will illustrate ways in which using the Zend Framework can greatly reduce development time and cost while improving the quality.

Table of Contents detailed table of contents

preface

acknowledgments

about this book

about the cover illustration

Part 1 The essentials

1. Introducing Zend Framework

1.1. Introducing structure to PHP websites

1.2. Why use Zend Framework?

1.2.1. Everything is in the box

1.2.2. Modern design

1.2.3. Easy to learn

1.2.4. Full documentation

1.2.5. Simple development

1.2.6. Rapid development

1.2.7. Structured code is easy to maintain

1.3. What is Zend Framework?

1.3.1. Where did it come from?

1.3.2. What’s in it?

1.4. Zend Framework design philosophy

1.4.1. High-quality components

1.4.2. Pragmatism and Flexibility

1.4.3. Clean IP

1.4.4. Support from Zend Technologies

1.5. Alternative PHP frameworks

1.6. Summary

2. Hello Zend Framework!

2.1. The Model-View-Controller design pattern

2.1.1. The model

2.1.2. The view

2.1.3. The controller

2.2. The anatomy of a Zend Framework application

2.2.1. The application directory

2.2.2. The library directory

2.2.3. The tests directory

2.2.4. The public directory

2.3. Hello World: file by file

2.3.1. Bootstrapping

2.3.2. Apache .htaccess

2.3.3. Index controller

2.3.4. View template

2.4. How MVC applies to Zend Framework

2.4.1. Zend Framework’s controller

2.4.2. Understanding Zend_View

2.4.3. The model in MVC

2.5. Summary

Part 2 A core application

3. Building a website with Zend Framework

3.1. Initial planning of a website

3.1.1. The site’s goals

3.1.2. Designing the user interface

3.1.3. Planning the code

3.2. Initial coding

3.2.1. The directory structure

3.2.2. The Bootstrap class

3.2.3. Running the application

3.3. The home page

3.3.1. The initial models

3.3.2. Testing our models

3.3.3. The home-page controller

3.4. Summary

4. Managing the view

4.1. Introducing the Two Step View and Composite View patterns

4.2. View handling with Zend_Layout

4.3. Integrating Zend_Layout into Places

4.3.1. Setup

4.3.2. Layout scripts

4.3.3. Common actions using placeholders

4.3.4. The homepage view script

4.4. Advanced view helpers

4.4.1. Controller integration

4.4.2. View script management

4.4.3. HTML header helpers

4.5. Summary

5. Ajax

5.1. Introducing Ajax

5.1.1. Defining Ajax

5.1.2. Using Ajax in web applications

5.2. A simple Ajax example

5.3. Using Ajax client libraries

5.4. Using Ajax with Zend Framework

5.4.1. The controller

5.4.2. The view

5.5. Integrating into a Zend Framework application

5.5.1. The Place controller

5.5.2. Adding review rating HTML to the view script

5.5.3. Adding JavaScript to the view scripts

5.5.4. The server code

5.6. Summary

6. Managing the database

6.1. Database abstraction with Zend_Db_Adapter

6.1.1. Creating a Zend_Db_Adapter

6.1.2. Querying the database

6.1.3. Inserting, updating, and deleting

6.1.4. Handling database-specific differences

6.2. Table abstraction with Zend_Db_Table

6.2.1. What is the Table Data Gateway pattern?

6.2.2. Using Zend_Db_Table

6.2.3. Inserting and updating with Zend_Db_Table

6.2.4. Deleting records with Zend_Db_Table

6.3. Using Zend_Db_Table as a model

6.3.1. Testing the model

6.3.2. Table relationships with Zend_Db_Table

6.4. Summary

7. User authentication and access control

7.1. Introducing authentication and access control

7.1.1. What is authentication?

7.1.2. What is access control?

7.2. Implementing authentication

7.2.1. Introducing Zend_Auth

7.2.2. Logging in using HTTP authentication

7.3. Using Zend_Auth in a real application

7.3.1. Logging in

7.3.2. A view helper welcome message

7.3.3. Logging out

7.4. Implementing access control

7.4.1. Introducing Zend_Acl

7.4.2. Configuring a Zend_Acl object

7.4.3. Checking the Zend_Acl object

7.5. Summary

8. Forms

8.1. Introducing Zend_Form

8.1.1. Integrated data filters and validators

8.1.2. Integrated error handling

8.1.3. Decorators to simplify markup

8.1.4. Plug-in loaders for customization

8.1.5. Internationalization

8.1.6. Subforms and display groups

8.2. Building a login form

8.2.1. Setting up paths

8.2.2. Our form view script

8.2.3. Updating the AuthController controller action

8.2.4. The basic login form class

8.3. Filtering and validation

8.3.1. Basic filtering and validation

8.3.2. Custom error messages

8.3.3. Internationalizing the form

8.3.4. Adding a custom validator

8.4. Decorating our login form

8.4.1. Zend_Form default decorators

8.4.2. Setting our own decorators

8.5. Summary

9. Searching

9.1.1. Key usability issue for users

9.1.2. Ranking results is important

9.2. Introducing Zend_Search_Lucene

9.2.1. Creating a separate search index for your website

9.2.2. Powerful queries

9.2.3. Best practices

9.3. Adding search to Places

9.3.1. Updating the index as new content is added

9.3.2. Creating the search form and displaying the results

9.4. Summary

10. Email

10.1. The basics of email

10.1.1. Email simplified

10.1.2. Dissecting an email address

10.2. Introducing Zend_Mail

10.2.1. Creating emails with Zend_Mail

10.2.2. Sending emails with Zend_Mail

10.3. Building a support tracker for Places

10.3.1. Designing the application

10.3.2. Integrating Zend_Mail into the application

10.3.3. Adding headers to the support email

10.3.4. Adding attachments to the support email

10.3.5. Formatting the email

10.4. Reading email

10.4.1. Collecting and storing email

10.4.2. Reading email with our application

10.5. Summary

11. Deployment

11.1. Setting up the server

11.1.1. Designing for different environments

11.1.2. Using virtual hosts for development

11.2. Version control with Subversion

11.2.1. Creating the Subversion repository

11.2.2. Checking out code from the repository

11.2.3. Committing changes to the repository

11.2.4. Updating a local working copy

11.2.5. Dealing with conflicts

11.2.6. Getting a clean copy from the repository

11.2.7. Using branches

11.2.8. Externals

11.3. Functional testing

11.3.1. Functional testing with Selenium IDE

11.3.2. Automating Selenium IDE tests

11.3.3. Functional testing with Zend_Http_Client

11.4. Scripting the deployment

11.5. Summary

Part 3 More power to your application

12. Talking with other applications

12.1. Integrating applications

12.1.1. Exchanging structured data

12.1.2. Producing and consuming structured data

12.1.3. How web services work

12.1.4. Why we need web services

12.2. Producing and consuming feeds with Zend_Feed

12.2.1. Producing a feed

12.2.2. Consuming a feed

12.3. Making RPCs with Zend_XmlRpc

12.3.1. Using Zend_XmlRpc_Server

12.3.2. Using Zend_XmlRpc_Client

12.4. Using REST web services with Zend_Rest

12.4.1. What is REST?

12.4.2. Using Zend_Rest_Client

12.4.3. Using Zend_Rest_Server

12.5. Summary

13. Mashups with public web services

13.1. Accessing public web services

13.1.1. Zend_Gdata

13.1.2. Zend_Service_Akismet

13.1.3. Zend_Service_Amazon

13.1.4. Zend_Service_Audioscrobbler

13.1.5. Zend_Service_Delicious

13.1.6. Zend_Service_Flickr

13.1.7. Zend_Service_Gravatar

13.1.8. Zend_Service_Nirvanix

13.1.9. Zend_Service_RememberTheMilk

13.1.10. Zend_Service_Simpy

13.1.11. Zend_Service_SlideShare

13.1.12. Zend_Service_StrikeIron

13.1.13. Zend_Service_Technorati

13.1.14. Zend_Service_Yahoo

13.2. Displaying ads with Amazon web services

13.2.1. The Amazon model class

13.2.2. The Amazon ads view helper

13.2.3. Caching the view helper

13.3. Displaying pictures from Flickr

13.3.1. The Flickr model class

13.3.2. Using Flickr in an action controller

13.4. Using Zend_Gdata for Google access

13.4.1. The YouTube API in an action controller

13.4.2. The video categories page

13.4.3. The video list page

13.4.4. The video page

13.5. Summary

14. Caching: making it faster

14.1. Benefits of caching

14.2. How caching works

14.3. Implementing Zend_Cache

14.3.1. Zend_Cache frontends

14.3.2. Zend_Cache backends

14.4. Caching at different application levels

14.4.1. Choosing what to cache

14.4.2. Optimal cache expiry

14.5. Cache tags

14.6. Summary

15. Internationalization and localization

15.1. Translating languages and idioms

15.1.1. Translating languages

15.1.2. Translating idioms

15.2. Using Zend_Locale and Zend_Translate

15.2.1. Setting the locale with Zend_Locale

15.2.2. Translating with Zend_Translate

15.3. Adding a second language to the Places application

15.3.1. Selecting the language

15.3.2. The LanguageSetup front controller plug-in

15.3.3. Translating the view

15.3.4. Displaying the correct date with Zend_Locale

15.4. Summary

16. Creating PDFs

16.1. Zend_Pdf basics

16.1.1. Creating or loading documents

16.1.2. Creating pages in your PDF document

16.1.3. Adding document meta-information

16.1.4. Saving the PDF document

16.2. Building a PDF report generator

16.2.1. Our report document model

16.2.2. Our report page model

16.3. Drawing text on the page

16.3.1. Choosing fonts

16.3.2. Setting the font and adding text

16.3.3. Adding wrapped text

16.4. Working with color

16.4.1. Choosing colors

16.4.2. Setting colors

16.5. Using Styles

16.6. Drawing shapes

16.6.1. Drawing lines

16.6.2. Setting up dashed lines

16.6.3. Drawing rectangles and polygons

16.6.4. Drawing circles and ellipses

16.7. Rotating objects

16.8. Adding images to the page

16.9. Drawing objects within clipping masks

16.10. Generating PDF reports

16.11. Summary

Appendix A: A whistle-stop tour of PHP syntax

Appendix B: Object-Oriented PHP

Appendix C: Tips and tricks

index

About the Technology

From rather humble beginnings as the “Personal Home Page” scripting language, PHP has found its way into almost every server, corporation, and dev shop in the world. On an average day, somewhere between 500,000 and 2 million coders do something in PHP. Even when you use a well-understood language like PHP, building a modern web application requires tools that decrease development time and cost while improving code quality. Frameworks such as Ruby-on-Rails and Django have been getting a lot of attention as a result.

For PHP coders, Zend Framework offers that same promise without the need to move away from PHP. This powerful collection of components can be used in part or as a whole to speed up the development process.

Zend Framework has the backing of Zend Technologies; the driving force behind the PHP programming language in which it is written. The first production release of the Zend Framework became available in July of 2007.

What's inside

This book includes a wealth of practical examples and explanations, including,

  • Zend Framework Model-View-Controller application architecture
  • Database management
  • Application security through filtering and validating data
  • Authorizing users and controlling access
  • Incorporating Ajax
  • Talking with other applications using web services
  • Speeding up pages with caching
  • Making your application international
  • Generating PDF content
  • Integrating other PHP libraries with the framework

About the reader

This book is aimed at the competent PHP developer who wants to master framework-driven web development. Zend Framework in Action goes beyond the docs but still provides quick access to the most common topics encountered in the development of web applications.

About the authors

Rob Allen has been programming with PHP for over seven years and is a member of the Zend Framework community. He is a contributor to the Zend Framework, developing the Zend_Config component with the help of many ideas from the mailing list. He has also written a popular getting-started tutorial available from www.akrabat.com. He holds a Masters degree in Electronic Engineering from the University of Birmingham and started out writing C++ Windows applications. He now concentrates solely on web-based applications in PHP. Rob is the Technical Director of Big Room Internet concentrating on the company's content management framework and future technologies.

Nick Lo is a web designer, developer, partner, and general 'wearer of many hats' with Ingredients, located in Byron Bay, Australia. Having formally trained as a designer, he initially taught himself programming to automate the more tedious aspects of printed catalog production. Since 1998 his involvement with website design and development has taken him further 'under the hood', working on a broad range of web-based applications from community portals to university research projects. His involvement in the Zend Framework began as an early participant in the community, gaining recognition through several online tutorials.

Steven Brown started using PHP in 1998 but has developed using many other languages including Java, Actionscript, Lingo and JavaScript. He has worked on desktop applications, multimedia CDs, websites, web applications, and more recently has worked on projects involving video and AJAX, while maintaining a focus on performance, reliability and security. Steven was introduced to the Zend Framework by Nick Lo and quickly adopted it as a replacement for his own core application code on several major projects. When he's not programming Steven enjoys driving or working on cars.


Buy
  • combo $44.99 pBook + eBook
  • eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Thorough, detailed. You couldn't ask for a better guide.

Matthew Weier O'Phinney, Zend Framework

A must-have resource. Picks up where the documentation leaves off.

David Hanson, D.A. Hanson Consulting LLC