Book Image

Zend Framework 2 Cookbook

By : Josephus Callaars, [email protected]
Book Image

Zend Framework 2 Cookbook

By: Josephus Callaars, [email protected]

Overview of this book

Zend Framework 2 is the latest creation of World Wide Web infrastructure company Zend Technologies Ltd. This new PHP framework comes with tons of features and an attractive way of creating applications. Not only is the overall usability of the technology much better, but it also makes your applications more testable, something that is often overlooked. "Zend Framework 2 Cookbook" will show you how applications are set up in Zend Framework 2 and how you can develop successfully in this massive framework. You will master features like Modules, Views, Controllers, and Authentication. The book also discusses the Event Manager, unit testing, and how to optimize your application. The book begins with a discussion about setting up Zend Framework 2, and you will also look at how the framework itself works. By the end of this book, you will be able to create entire secure applications on your own and make sure they are tested and optimized for performance as well. You will learn about sending and receiving e-mails, translation and localization of the application, and how to set up the framework on a Linux web server. You will also learn how to display data from the application to the user by using different display strategies and renderings. The creation of modules will also be discussed. Then, you will move on to look at how to authenticate users and make sure the developer knows how to pick the best method available. Unit testing, debugging, and enhancing the performance will also be covered in this book. "Zend Framework 2 Cookbook" is a perfect book for anyone who wants to start developing with Zend Framework 2.
Table of Contents (17 chapters)
Zend Framework 2 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

A couple of years ago I was introduced to Zend Framework 1 by a friend of mine, and since then I have been a fan. Although the first framework was a real bulky framework with not much documentation, I feel that the second version of the framework improved greatly. The incredible toolshed full of features, makes this framework (personally) one of the best frameworks to work in.

But as we all probably know, because of its incredibly vast library of features the learning curve can appear very steep. That is why I felt the need to write about all the important parts of the framework, in bite-size pieces that don't overwhelm someone (you in this case) who wants to learn it.

What this book covers

Chapter 1, Zend Framework 2 Basics, talks about how we can set up a small application and run it. The dependency injection and configuration are also handled.

Chapter 2, Translating and Mail Handling, explains the importance of internationalization and localization, and the overall handling of sending and receiving of mails in our applications.

Chapter 3, Handling and Decorating Forms, demonstrates how forms are created. After that it talks about filtering, validation, and decoration of forms.

Chapter 4, Using View, covers one of the most important parts of the framework that will be discussed here, setting and rendering of the View.

Chapter 5, Configuring and Using Databases, gives out the configuration and explanation of databases that will give us an insight into how we can fully utilize them in our application.

Chapter 6, Modules, Models, and Services, mainly discusses how modules are built up, models can be hydrated, and services are defined.

Chapter 7, Handling Authentication, delves into the different ways of authenticating users and how we can create our own authentication method.

Chapter 8, Optimizing Performance, discusses the use of caching and the methods available to cache output, opcode, and how to use plugins.

Chapter 9, Catching Bugs, teaches us how to debug applications, handle exceptions, and log stuff.

Appendix, Setting up the Essentials, shows where we can find the documentation, how to set up a development environment, and shows how the composer works.

What you need for this book

To follow the book in the best possible way I would recommend using a Linux-based web server, as most of the recipes are more Linux oriented than Windows. If you are a Windows user you'll probably be better off installing a virtual machine with Linux on it, or installing a Zend Server community edition to make sure your machine is compatible for Zend Framework 2 development (you can also do this without Zend Server, but it is just more convenient).

Who this book is for

Zend Framework 2 Cookbook is for PHP developers who are fairly advanced in PHP programming. It will also be useful for developers who have a keen interest in expanding their knowledge outside the boundaries of simply scripting pages together. As unit testing and MVC will be discussed, it is beneficial for the reader to know what these technologies are, although experience with developing applications is not necessarily essential.

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, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can either get the flags from a message by using the getFlags() method, or by using the hasFlag() method."

A block of code is set as follows:

<?php
echo $this->dateFormat(
    // Format the current UNIX timestamp.
    time(),

    // Our date is to be a LONG date format.
    IntlDateFormatter::LONG,

    // We want to omit the time, defining this is 
    // optional as the default is NONE.
    IntlDateFormatter::NONE

);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

SampleModule/
  config/
    module.config.php
  language/
  src/
    SampleModule/
      Controller/
        IndexController.php
  view/
    samplemodule/
      index/
        index.phtml
  Module.php

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

php composer.phar update

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: "After we have done all that we can, click on OK and you can choose a location to save our file."

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.

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 to address it.