Easy PHP Websites with the Zend Framework (2009) doc - Pdf 15

Jumpstart your web development career using popular technologies including PHP
and MySQL, Ajax, RSS, PayPal™, the Facebook Platform®, Amazon Web Services™,
the Google Maps API™, the Google Analytics™ web analytics service, the Google
AdSense™ and Google AdWords™ advertising services, and more!
Easy PHP Websites
with the Zend Framework
W. Jason Gilmore
Bestselling author of Beginning PHP and MySQL, Third Edition
WJ Gilmore, LLC
www.easyphpwebsites.com
Download at Boykma.Com
Easy PHP Websites
with the Zend Framework
W. Jason Gilmore
Download at Boykma.Com
Easy PHP Websites with the Zend Framework
Copyright © 2009 W. Jason Gilmore
Published by
W.J. Gilmore, LLC
1373 Grandview Avenue, Suite 214
Columbus, Ohio 43212
All rights reserved. No part of this publication may be reproduced or transmitted in any form or by
any means, electronic, mechanical, photocopying, scanning, recording or otherwise, except as permit-
ted under the 1976 United States Copyright Act, without the prior written permission of the copyright
owner and the publisher.
Trademarks: Trademarked names may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, we use the names only in an editorial fashion and to no ben-
et of the trademark owner, with no intention of infringement of the trademark. Zend is a trademark
of Zend Technologies Ltd. Amazon Web Services™ is a trademark of Amazon.com, Inc. Facebook®
is a registered trademark of Facebook Inc. PayPal® is a registered trademark of PayPal, Inc. Google
Maps API™, GoogleAdSense™, and Google AdWords™ are trademarks of Google Inc. All other

Step #1. Installing Apache, MySQL, and PHP on Windows 2
Step #2. Testing Your Installation 13
Step #3: Choosing a Code Editor 14
Step #4. Exploring Other Useful Software 17
Step #5. Choosing a Web Hosting Provider 19
CHAPTER 2. Introducing PHP 23
Step #1. Creating Your First PHP-Enabled Web Page 23
Step #2. Publishing Spreadsheet Data to the Web 38
Displaying Data in a Table 41
Step #3. Managing Your Site Design Using Templates 47
CHAPTER 3. Interacting With Your Users 51
Step #1. Creating a Contact Form 52
Step #2. Validating User Input 56
Step #3. Repopulating Form Data 65
Step #4. Sending Form Data via E-mail 67
Step #5. More on Securing User Input 72
CHAPTER 4. Introducing MySQL 75
Step #1. What Is a Relational Database? 76
Step #2. Introducing MySQL 77
Step #3. Introducing phpMyAdmin 83
Step #4. Moving Your Data to MySQL 86
Step #5. Connecting Your Website to MySQL 88
Step #6. Restricting Access 103
CHAPTER 5. Introducing the Zend Framework 105
Step #1. What Is a Web Framework? 106
Step #2. Introducing the Zend Framework 112
Step #3. Installing the Zend Framework 115
Step #4. Testing Your Installation 121
Step #6. Creating the Website Layout 125
Download at Boykma.Com

Download at Boykma.Com
Step #3. Searching for Products 239
Step #4. Customer Reviews 241
CHAPTER 11. Enhancing the User Interface with Ajax 245
Step #1. Introducing JavaScript 246
Step #2. Introducing Ajax 261
CHAPTER 12. Extend Your Website with RSS and Facebook 263
Step #1. Building and Publishing RSS Feeds 264
Step #2. Introducing the Facebook Platform 269
Step #3. Building Your First Facebook Application 274
Step #4. Introducing the Facebook PHP Client Library 276
Step #5. Creating a Facebook Platform Controller 277
Step #6. Creating a Facebook Prole Tab 280
Step #7. Sending a Facebook User Notication 282
Step #8. Adding Facebook Status Updates 283
Step #9. Deploying Your Facebook Application 285
CHAPTER 13. Monitor Trafc and Manage Ads with Google 287
Step #1: Monitoring Trafc with Google Analytics 287
Step #2. Advertising with Google AdWords 294
Step #3: Earning Money with Google AdSense 301
CHAPTER 14. Accepting Online Payments with PayPal 305
Step #1. Integrating PayPal Website Payments Standard 305
Step #2. Exploring Third-Party E-Commerce Solutions 309
CHAPTER 15. Introducing Zend_Tool 315
Step #1. Conguring Zend_Tool 315
Step #2. Creating and Managing Projects with Zend_Tool 316
Download at Boykma.Com
Download at Boykma.Com
Download at Boykma.Com
About the Author

always make this process much less painful.
Chris Davis did an excellent job as a tech reviewer, catching numerous mistakes made as I fought
with both code and prose.
Carlene DeFiore helped out immensely, reviewing chapters, helping with promotional strategy, and
keeping me well fed.
Countless other individuals played key advisory roles in helping this book to nally see the light. In
alphabetical order, they include David Futato, Jonathan Hassell, Stu Johnson, and Matt Zenko. I'd
also like to thank the great people at the Grandview Heights Fifth Third Bank and U.S. Post Ofce for
helping get the business off the ground.
I'd perhaps never have gotten into the publishing business without the help of Apress cofounder Gary
Cornell, who rst contacted me back in 2000 to write a book for what was then a very small but dar-
ing computer book upstart (one which has since grown into a rather large but still daring publisher).
He played a pivotal role in my development as an author and later an editor for Apress. Thank you
Gary.
Last but certainly not least, I'd like to thank you dear reader, for having enough faith to trade your
hard-earned money for this book.
Download at Boykma.Com
Introduction
Picture spending an evening hanging out with a group of gregarious savants from around the globe.
Over hors d'oeuvres you debate the merits of globalism, and split time during dinner extolling the
ferocity of the 2008 Pittsburgh Steelers defense and listening intently to two physicists argue over the
plausibility of time travel. The evening concludes with no less than four renditions of Beethoven's
Symphony no. 7, including electronica and hip-hop versions. No doubt, an evening such as this would
leave even the most tempered of socialites admitting to being among raried company. This also hap-
pens to be an evening any one of us could spend while surng the World Wide Web.
We're living in the midst of the most prolic democratization of knowledge in the history of the
world. In the twenty years since Tim Berners-Lee's authoring of the paper which led to the creation of
the World Wide Web, we've progressed from a civilization dependent upon the often meager resourc-
es of small town libraries and yellow journalism of local media outlets to one which has practically
all of the information in the history of the world available at the cost of just a few keystrokes. Never

resource-challenged reader who was looking to maximize his every second spent working towards
the goal of building a powerful website. Accordingly, each chapter is devoted to accomplishing a very
specic, desired task, such as processing payments with PayPal, building a Facebook application,
integrating Google Maps into a website, and building a product catalog using the Amazon Associates
Web Service. You'll also gain from practical instruction on topics pertinent to the logistical-side of
Web development, such as creating an ideal development environment, what to keep in mind when
choosing a web hosting provider, and how to take advantage of services such as Google Analytics,
Google AdWords, and Google AdSense.
In an attempt to keep the instruction topical and applicable to current trends, the book guides you
through the hypothetical creation of a social networking website for video game enthusiasts. You'll
start simple, learning how to convert a spreadsheet used to track your video game collection into a
format capable of being viewed via the Web. From there the project builds in ambition, migrating the
collection to a MySQL database, and subsequently turning to the popular Zend Framework in order to
more effectively manage user accounts, process data submitted via Web forms, and send e-mail. The
nal six chapters show you how to integrate the Zend Framework with popular third-party services
such as Google Maps, Amazon.com, Facebook, and PayPal to build an even more compelling web-
site. Of course, you're free to pick-and-choose among these topics, using the chapters what you nd
most appealing and disregarding the rest.
Incidentally, the video game theme wasn't altogether contrived. My own interest in video games led
to the creation of GameNomad (
http://www.gamenomad.com/), a social networking website which
gives gamers and their like-minded friends tools for managing their respective game collections.
Quite a bit of the code and many examples are based on the website, and in fact you'll nd quite a bit
of the code used to power the GameNomad website within the source code download.
Book Contents
Easy PHP Websites with the Zend Framework is broken into fourteen chapters, and supplemented
with several videos available to readers via the website
http://www.easyphpwebsites.com/.
Chapter 1. Conguring Your Development Environment
In this introductory chapter you'll learn how to create the ultimate development environment. In addi-

Chapter 6. Talking to the Database with Zend_Db
Chapter 4 showed you how to write queries which PHP which made it possible to interact with a
MySQL database. Although unquestionably useful, if you're like me there was something oddly un-
natural about mixing PHP and SQL code together within a single script. In this chapter I'll show you
how to have your cake and eat it too by using the Zend_Db component to interact with MySQL using
purely PHP code.
Chapter 7. Processing Forms and Sending Email
This chapter extends what was learned in Chapter 3, using the Zend Framework to process user-sub-
mitted data. You'll also learn about the Zend Framework's powerful built-in data validation and lter-
ing features, how to send e-mail using the Zend_Mail component, and how to foil spammer activity
using a mechanism known as a CAPTCHA.
Chapter 8. Managing Your User Community
These days, a successful web-based venture is often the direct result of your ability to create a suc-
cessful online community. In this chapter you'll learn how to build fundamental community mecha-
nisms such as user registration, user login and logout, password recovery, user prole display, and
connecting users via a simple social networking mechanism.
Chapter 9. Integrating Google Maps
Google's release of an interface to the popular Google Maps mapping solution opened the oodgates
for thousands of location-based websites. In this chapter you'll learn how to use this API to integrate
Download at Boykma.Com
Google's mapping features into your own website. You'll also learn how to use the Google Geocoder
to convert user's mailing addresses into latitudinal and longitudinal coordinates.
Chapter 10. Introducing Amazon Associates Web Service
The Amazon Associates Web Service (AWS) offers developers around the globe with a great way to
earn revenue by advertising Amazon's product catalog in new and interesting ways. In this chapter
you'll learn how to take advantage of this program to create your own custom catalog. You'll also
learn how to retrieve Amazon reviews for a particular product, and even how to use a neat Zend
Framework view helper feature to tie a visually appealing starred effect to each review.
Chapter 11. Enhancing the User Interface with Ajax
Enhancing the user experience by enhancing the interface is all the rage these days, a process most

Downloading the Source Code
The source code for this book is available via the website http://www.easyphpwebsites.com/.
Contact the Author
Over the past decade I've responded to thousands of reader e-mails, and eagerly look forward to
responding to yours. E-mail me at [email protected] with your questions and comments
regarding this book, or anything else that strikes your fancy.
Download at Boykma.Com
CHAPTER 1
Conguring Your Development Environment
Chances are you'll be relying on a web hosting provider to manage your website, however for reason
of convenience and efciency you'll want to develop the website on a personal workstation or laptop.
In this chapter I'll show you how to install Apache, PHP and MySQL on the Windows XP and Win-
dows Vista operating systems. You'll also be introduced to several integrated development environ-
ments (IDEs) and other utilities which will prove invaluable when building your web applications, as
well as become acquainted with the issues you'll need to keep in mind when selecting a web hosting
provider.
VIDEO. Introducing PHP and MySQL
Just what makes the PHP language and MySQL database so popular? Why are they so com-
monly used together to build websites both large and small? This video introduces you to
PHP and MySQL, focusing on the features which have turned open source projects with
modest beginnings into two of the world's game-changing technologies. Watch the video at
http://www.easyphpwebsites.com/zfw/videos/.
Chapter Steps
The goals of this chapter are accomplished in ve steps:
• Step #1. Installing Apache, MySQL and PHP on Windows: In this step you'll learn how
to install Apache, PHP and MySQL both the easy way (using an automated installer called
XAMPP) and the hard way (manually) on the Windows XP or Vista operating systems.
Special attention is paid to troubleshooting confusing installation and conguration issues on
the Windows platform. Don't worry if your laptop or computer is a few years old, because the
software can run quite ably with minimal resources.

able to go a long way towards building and managing powerful websites even without this additional
installation and conguration knowledge.
Installing Apache, PHP, and MySQL: The Easy Way
Over the years, I've received perhaps hundreds, if not thousands of reader emails. The overwhelming
majority of these readers wrote with support questions specic to the problems they were encounter-
ing while installing Apache, PHP, or MySQL, or getting all three to properly communicate with one
another. It isn't that installing them is particularly difcult, but rather that if something goes wrong, it
can be difcult to troubleshoot the problem.
In response to the frustrating issues encountered by newcomers to installing this sort of software,
developers Kay Vogelgesang and Kai Seidler got together to create XAMPP, an automated solution
which installs Apache, PHP, MySQL for you. It removes all of the potential frustration occasionally
encountered when installing one or all of these applications, and is available for all major platforms,
including Windows (98, NT, 2000, 2003, XP, and Vista), Linux (known to work on Debian, man-
drake, RedHat, and SuSE), Mac OS X, and Solaris.
Installing XAMPP Lite
To install XAMPP, navigate to http://www.apachefriends.org/en/xampp.html and click upon
the appropriate platform-specic link. In addition to Apache, MySQL, and PHP you'll see each
package comes with a variety of additional software, including an FTP server, the Webalizer trafc
analysis program, and phpMyAdmin (introduced in the later section, "Introducing phpMyAdmin"). If
you're running Windows, you have the option of foregoing the installation of this additional software
by downloading XAMPP Lite, which installs just Apache, MySQL, Perl, PHP, and phpMyAdmin. In
this section I'll show you how to install XAMPP Lite.
Download at Boykma.Com
3CHAPTER 1 • CONFIGURING YOUR DEVELOPMENT ENVIRONMENT
Once you've downloaded XAMPP Lite, double-click the downloaded le's icon to begin the extrac-
tion process. The extraction path will default to the same directory as the installer's download loca-
tion. I suggest changing this location to your
C:\ drive, as shown in Figure 1-1. A directory named
xampplite being created along that path, with Apache, PHP and MySQL along with various other
items being placed in this directory.

lease having the highest version number and having a title of Win32 Binary without crypto (no
mod_ssl) (MSI Installer). Select a location of your choosing (I usually place installers on the
desktop so I can easily sweep them into the Recycle Bin afterwards), and once downloaded, double-
click the icon to begin the installation process.
Preliminary Installation Procedures
You'll rst be greeted with a screen welcoming you to the Apache Installation Wizard. Click Next >
to continue. Next up is a screen prompting you to read and accept the Apache license. Take some time
to familiarize yourself with the license, accept the terms, and click
Next > to continue. Next you'll
be prompted to peruse the README le, which contains numerous valuable notes regarding running
Apache on Windows. Take a moment to read this text, and click Next > to continue.
Network Information
At this point you'll be prompted to provide three items of information (Figure 1-3): the server's net-
work domain, the server name, and the administrator's e-mail address. Newcomers tend to get hung
up at this stage, however the solution is simple: just input
localhost for both the network domain
and server name, and leave the administrator's e-mail address as-is.
The term
localhost is an alias for the address 127.0.0.1, which happens to be the address used to
identify the local computer. Therefore once Apache is running, any calls to http://localhost/ will
prompt the local Apache installation to respond.
Regarding the Administrator's e-mail address, in certain congurations this address is provided to
users in the case of a server error, however because I presume this Apache installation will be used for
development purposes, you and your team will be the only users interacting with the server, and it's
likely you'll know who to contact in such cases! That said, ll in any e-mail address you please.
At the conclusion of this screen, you're asked whether you'd like to install Apache as a service, mean-
ing it will start and stop automatically when Windows is booted and shutdown, respectively. This will
also congure Apache to listen on port 80, the default for web servers. Alternatively, you can install
Apache in a fashion that will require you to start and stop it manually, and run it on a non-standard
Download at Boykma.Com


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status