Book Image

Zend Framework 2 Application Development

By : Christopher Valles
Book Image

Zend Framework 2 Application Development

By: Christopher Valles

Overview of this book

<p>Zend Framework 2 has a flexible architecture that lets us build modern web applications and web services easily. It also provides an easy-to-use, high quality component library that is designed to be used the way you want. It's easy to get started and produce a powerful and professional looking website with Zend Framework 2 Application Development. Exploring real life applications, we will explore the Zend Framework 2 components, as well as throwing some light on best practices and design concerns faced when building complex MVC applications.Zend Framework 2 Application Development is a hands-on guide to building your application. We will explore the components of this new version of the framework and discover how to use each component, the options available, and how to get the most from each component. Whilst learning everything you need to know, we’ll even create our own social network. We will also learn to engineer an application using an API-centric approach, broadly used today to build applications that work seamlessly on desktops, mobiles and tablets. We will learn how to filter and validate data, interact with databases to retrieve and store data, handle and manipulate file uploads, interact with other websites, deal with spam, and also protect your APIs using OAuth authentication whilst allowing people from all over the world to interact with your application. Zend Framework 2 Application Development is your guide to everything you need to know to build applications of any size for big and small companies alike, whilst using the right components for the job.</p>
Table of Contents (21 chapters)
Zend Framework 2 Application Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
4
The First Request/Response – Building the User Wall
5
Handling Text Content – Posting Text
6
Working with Images – Publishing Pictures
8
Dealing with Spam – Akismet to the Rescue
Index

Preface

Nowadays, the programming scene is full of frameworks, and they move really fast, providing more and more functionalities. When we have to choose a framework, every developer has different requirements. But usually in the business environment we want to choose something that assures somehow a continuity on the framework, stability, and a good community behind.

Zend Framework is well known for being a really stable framework chosen by a lot of companies from really big to small ones. They have a huge community behind and a lot of people contribute in a way or another.

The first version of ZF was released in 2007, and since then they continue updating the project. Right now the code is old and tied to solutions that made sense in the past; the technology has advanced and new techniques and approaches have appeared. In this situation it makes perfect sense to try to incorporate them to the framework, but integrating these with the old code is just a nightmare because too many things have to be changed. In order to get the most from the new techniques, the solution was to do a new framework from scratch and implement the new concepts from the core and build everything around it.

That's what happened in September 2012, the first release of ZF2 was launched after a lot of work, discussions, and lines of code, and now we have it available to build the next generation of online services.

This new version was created from scratch using the best approaches for every problem and is really fresh and flexible. All the components have been revised and a lot of them rewritten, they also solved well-known problems from ZF1.

In this book we will review all the changes made in ZF2. The book is written with a hands-on approach, so you will learn the concepts while programming and building something that is actually usable. We will create a social network from scratch using 90 percent of all the components available in ZF2. So, we will cover a huge part of it, and definitely all you will need in the future is to write your applications.

What this book covers

Chapter 1, Let's Build a Social Network, explains how we can create or build a social network. It also covers how we can architect a social network.

Chapter 2, Setting Up the Environment, is important because if you do not understand it you will not be able to do anything! Let's see how to use Vagrant and virtual machines.

Chapter 3, Scratching the Surface of Zend Framework 2, is essential to get the knowledge of the basic components of the framework and also to help understand concepts introduced later on.

Chapter 4, The First Request/Response – Building the User Wall, is essential in a social network. It is where the users can see the content, and where we can see how the API-centric approach works.

Chapter 5, Handling Text Content – Posting Text, is the simplest action a user can do. We will learn how to create forms and validate them.

Chapter 6, Working with Images – Publishing Pictures, is something people love to do on social networks. We will learn how to handle images and file uploads.

Chapter 7, Dealing with URLs – Posting Links, is essential to share things we found on the Internet. This is the perfect excuse to see how to scrap contents of other websites and create custom validators.

Chapter 8, Dealing with Spam – Akismet to the Rescue, explains how to protect ourselves from the spammers in the Internet.

Chapter 9, Let's Read Feeds – A News Reader, is something we use almost every day. Why don't we integrate it and learn how to deal with feeds on our social network?

Chapter 10, Sign Up, is the basic thing people have to do to start using a service that will store data tailored to them. And, as usual, we will have to send the typical confirmation e-mail. How do we accomplish that task?

Chapter 11, Log In, is something we are used to doing and our users will need to do. We will see how to be sure that our users are who they say and authenticate them.

Chapter 12, Sending E-mails, is a link everyone has used at least once. We will cover in-depth the e-mail sending mechanism and we will see how to organize the views for e-mails.

Chapter 13, OAuth 2.0 Protocol Securing our API, is essential if we don't want people to use it in the Web for which it was not designed. As we will expose the API to the world, we should learn how to protect it.

What you need for this book

For this book, you will need a computer, of course. In terms of software required, you don't have to be worried; all the components we use are open source, and everything is provided on the virtual machine we will set up in Chapter 2, Setting Up the Environment. The only thing you will need to do manually is install the last version of VirtualBox available for your operating system; the rest will be done almost automatically by the Vagrant scripts we provide.

Who this book is for

This book is for developers that want to start using Zend Framework 2 and want to build applications of an important size. We will cover a different approach on application architecture so this will also be helpful for you.

You don't need to have any experience with the framework or with Zend Framework 1, but if you have, it will be easier for you; but remember, it's not required. A good and solid knowledge of PHP 5.3 and an object-oriented paradigm is required because the whole framework is based on that and is strongly object oriented.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "On implementing this functionality, we will see how the new Zend\Form element handles the upload of files and how to process them."

A block of code is set as follows:

config.vm.box = "ubuntu-12.04"
config.vm.box_url = "http://files.vagrantup.com/precise64.box"
config.vm.network :private_network, ip: "192.168.56.2"

Any command-line input or output is written as follows:

cd /var/source-api
php composer.phar self-update
php composer.phar install
cd /var/source-client
php composer.phar self-update
php composer.phar install

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "This validator belongs to the Email field."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase to address it.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best