Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
MEAP Edition
Manning Early Access Program
Copyright 2007 Manning Publications
For more information on this and other Manning titles go to
www.manning.com
Licensed to Menshu You <dollequatki@gmail.com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Table of Contents
Part 1: The essentials
1. Introducing the Zend Framework
2. Hello Zend Framework!
Part 2: A core application
3. Building a web site with the Zend Framework
4. Ajax
5. Managing the database
6. User authentication and authorisation
7. Forms
8. Searching
9. Email
10. Deployment
Part 3: More power to your application
11. Talking with other applications
12. Mash ups with public web services
13. Caching: making it faster
14. Internationalization and localization
15. Creating PDFs
16. Integrating with other PHP libraries
Appendix A. Stuff you (should) already know
Appendix B. System-specific gotchas
Appendix C. Zend Framework Core Components reference
Licensed to Menshu You <dollequatki@gmail.com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
1
Introducing the Zend Framework
PHP has been used to develop dynamic websites for over 10 years. Initially all PHP websites were written as
PHP code interspersed within HTML on the same page. This works very well initially as there is immediate
feedback and for simple scripts this appears to be all that is needed. PHP grew in popularity through versions 3
and 4, and so it was inevitable that larger and larger applications would be written in PHP. It became obvious
very quickly that intermixing PHP code and HTML was not a long term solution for large websites.
The problems are obvious in hindsight: maintainability and extensibility. Whilst PHP intermixed with
HTML allows for extremely rapid results, in the longer term it is hard to continue to update the website. One
of the really cool features of publishing on the web is that it is dynamic with content and site layouts changing.
Large websites change all the time. The look and feel of the site is updated regularly. New content is added
and content is regularly re-categorized as the needs of the users (and advertisers!) change. Something had to
be done!
The Zend Framework was created to help ensure that the production of PHP based websites is easier and
maintainable in the long term. It contains a rich set of reusable components containing everything from a set of
Model-View-Controller application components to PDF generation. Over the course of this book, we will look
at how to use all the components within the context of a real website.
1.1 Introducing structure to PHP websites
The solution to this tangled mess of PHP code and HTML on a website is structure. The most obvious
introduction to structured applications within PHP sites is applying the concept of “separation of concerns”.
This means that the code that does the display should not be in the same file as the code that connects to the
database and collects the data as shown in Figure 1.1.
Licensed to Menshu You <dollequatki@gmail.com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Figure 1.1: The organization of a typical PHP file created by a novice interleaves HTML and PHP code in a linear fashion as the file is
created.
The first stages of introducing structure to a website’s code happen by default for most developers; the
concept of reusability dawns. Generally, this means that the code that connects to the database is separated into
a file called something like db.inc.php. Then it seems logical to separate out the code that displays the common
header and footer elements on every page. Functions are introduced to help solve the problem of global
variables affecting one another
As the website grows, common functionality is grouped together into libraries. Before you know it, the
application is much easier to maintain and adding new features becomes possible again. This stage lasts for a
little while and the website continues to expand until it gets to the point where the supporting code is so large
that you can’t hold a picture of how it all works in your head.
PHP coders are used to standing on the shoulders of giants as our language provides easy access to
libraries such as the GD image library, the many database client access libraries and even system specific
libraries such as COM on Windows. It was inevitable that Object-Oriented Programming would enter the PHP
landscape. Whilst classes in PHP4 provided little more than glorified arrays, PHP5 provides excellent support
for all the things you’d expect in an object oriented language. Hence there are visibility specifiers for class
members (public, private and protected) along with interfaces, abstract classes and support for exceptions.
The improved object-oriented support allows for more complicated libraries (known as frameworks) to
evolve, such as the Zend Framework which supports a way of organizing web application files know as the
MVC design pattern. This is shown in Figure 1.2.
Licensed to Menshu You <dollequatki@gmail.com>