In 2005, Andi Gutmans of Zend Technologies announced Zend’s PHP Collaboration Project, and with it launched Zend Framework. By March 2006, there was some initial code, and version 1.0 was released in July 2007 with regular releases since then. Zend Framework has provided PHP with a high-quality framework that is different from most others due to its use-at-will philosophy, allowing the developer to pick and choose which parts to use for any given project.
This book shows how to use Zend Framework to your best advantage, and the techniques are demonstrated on an example website that is developed over the course of the book. We look at the major components of Zend Framework and show how to use each one in the context of a real-world application. As a result, this book supplements the online manual’s functional view of the framework by showing you how it all fits together, allowing you to produce high-quality websites and applications.
This book is for PHP developers who want to or are using Zend Framework. As Zend Framework has a use-at-will philosophy, not all chapters will be useful to every reader immediately. However, we believe that all readers will gain something from every chapter, even if you have to read it again to pick up the details when you start using that component!
This is not a beginner’s book; we assume that you are familiar with PHP and have an understanding of object-oriented programming. Appendix A, “A Whistle-Stop Tour of PHP Syntax,” and appendix B, “Object-Oriented PHP,” provide a useful overview of the fundamentals, but they are not substitutes for a full book on the subject.
In addition to this book, the Zend Framework website at http://framework.zend.com/ is an excellent resource. The online manual at http://framework.zend.com/manual/en/ is the definitive reference documentation for all the components in the framework. For help and discussion on Zend Framework, we recommend subscribing to the mailing lists. The details can be found at http://framework.zend.com/wiki/display/ZFDEV/Contributing+to+Zend+Framework, and the archives are at http://framework.zend.com/archives. Finally, interactive, real-time chat about Zend Framework can be found on the Freenode IRC network in the #zftalk channel.
This book is organized into three parts. Part 1 introduces Zend Framework and shows how to implement a simple “hello world” application using Zend Framework components. Part 2 looks at the components in the framework that are useful to most web applications, and part 3 introduces the less frequently used components that will be cherry-picked for particular projects.
Chapter 1 looks at what components Zend Framework provides to help us build web-sites quickly and efficiently. It also looks at why we use the framework in the first place and what advantages it brings.
Chapter 2 puts some code on the table. Starting slowly, we build the simplest, complete website that we can using the Model View Controller (MVC) design pattern. This chapter sets the stage and introduces core concepts about the code and design of Zend Framework that serve as a foundation for parts 2 and 3.
Chapter 3 develops the initial design and code for the Places to take the kids!, a real-world community website using Zend Framework. We start by looking at bootstrapping and code organization and build up to the home page controller code.
Chapter 4 builds on the work in Chapter 3 to develop the frontend look and feel of the website. We use the Zend_View and Zend_Layout components to develop a Composite View system that separates the display elements that are specific to a given page from those that are common across all pages.
Chapter 5 introduces Ajax from first principles, then looks at integrating an Ajax request into a Zend Framework MVC application.
Chapter 6 considers interaction with a database, using the Zend Framework database components, from database abstraction to the higher-level table abstraction.
Chapter 7 is all about the users and how to authenticate access and then control their access to specific sections of a website.
Chapter 8 explains how to take control of forms on your website by using the Zend_Form component.
Chapter 9 tackles the thorny subject of site-wide searching to help your users find what they are looking for on your website.
Chapter 10 discusses the Zend_Mail component that allows for sending and reading of email.
Chapter 11 completes this part of the book by looking at management issues including version control, deployment, and testing.
Chapter 12 looks at integrating web applications together with XML_RPC and REST protocols. It also looks at integrating RSS and Atom feeds into an application.
Chapter 13 explains how to add value to your website by integrating the plethora of data from public web services available on the Internet.
Chapter 14 goes behind the scenes and shows how caching can be used to speed up a website and allow an application to scale.
Chapter 15 considers how to provide a multilingual website that is also aware of the local idioms that your users’ expect on a polished website.
Chapter 16 shows how to create PDF documents with text and graphics in them.
Appendix A provides a short tour of the PHP syntax, mostly aimed at people coming from another language.
Appendix B describes the PHP5 object model and so provides a leg up for those who have mainly programmed procedurally before using Zend Framework.
Appendix C offers tips and tricks that allow you to develop your Zend Framework applications more easily.
All source code in the book is in a fixed-width font like this, which sets it off from the surrounding text. For most listings, the code is annotated to point out the key concepts, and numbered bullets are sometimes used in the text to provide additional information about the code. We have tried to format the code so that it fits within the available page space in the book by adding line breaks and using indentation carefully. Sometimes, very long lines will include line-continuation markers.
Source code for all the working examples is available for download from http://www.manning.com/ZendFrameworkinAction. A readme.txt file is provided in the root folder and also in each chapter folder; they provide details on how to install and run the code. In cases where we have not been able to show every detail in the book, the accompanying source code has the full details. You will need a working PHP installation on the Apache web server and a MySQL database for the examples to run.
Purchase of Zend Framework in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the lead author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/ZendFrameworkinAction or www.manning.com/allen. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful dialog between individual readers and between readers and the authors can take place. It’s not a commitment to any specific amount of participation on the part of the authors, whose contribution to the AO remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions lest their interest stray!
The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.
By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering. According to research in cognitive science, the things people remember are things they discover during self-motivated exploration.
Although no one at Manning is a cognitive scientist, we are convinced that for learning to become permanent it must pass through stages of exploration, play, and, interestingly, retelling of what is being learned. People understand and remember new things, which is to say they master them, only after actively exploring them. Humans learn in action. An essential part of an In Action guide is that it is example-driven. It encourages the reader to try things out, to play with new code, and explore new ideas.
There is another, more mundane, reason for the title of this book: our readers are busy. They use books to do a job or to solve a problem. They need books that allow them to jump in and jump out easily and learn just what they want just when they want it. They need books that aid them in action. The books in this series are designed for such readers.