Working with Zend Framework 2.0

Instant Zend Framework 2.0


August 2013

$12.99

Designed for developers who want to learn Zend Framework fast, using a hands-on practical approach rather than dry theory. By the end of this book you’ll have learned how to build a complete data-driven web application.

(For more resources related to this topic, see here.)

So, what is Zend Framework?

Throughout the years, PHP has become one of the most popular server-side scripting languages on the Internet. This is largely due to its steep learning curve and ease of use. However, these two reasons have also contributed to many of its shortcomings.

With minimal restrictions on how you write code with this language, you can employ any style or structure that you prefer, and thus it becomes much easier to write bad code.

But there is a solution: use a framework!

A framework simplifies coding by providing a highly modular file organization with code libraries of the most common scripting in everyday programming. It helps you develop faster by eliminating the monotonous details of coding and makes your code more re-usable and easier to maintain.

There are many popular PHP frameworks out there. A number of them have large, open source communities that provide a wide range of support and offer many solutions. This is probably the main reason why most beginner PHP developers get confused while choosing a framework.

I will not discuss the pros and cons of other frameworks, but I will demonstrate briefly why Zend Framework is a great choice.

Zend Framework (ZF) is a modern, free, and open source framework that is maintained and developed by a large community of developers and backed by Zend Technologies Ltd, the company founded by the developers of PHP.

Currently, Zend Framework is used by a large number of global companies, such as BBC, Discovery, Offers.com, and Cisco. Additionally, many widely used open source projects and recognized frameworks are powered by Zend Framework, such as in the case of Magento, Centurion, TomatoCMS, and PHProjekt. And lastly, its continued development is sponsored by highly recognizable firms such as Google and Microsoft.

With all this in mind, we know one thing is certain—Zend Framework is here to stay.

Zend Framework has a rich set of components or libraries and that is why it is also known as a component framework. You will find a library in it for almost anything that you need for your everyday project, from simple form validation to file upload. It gives you the flexibility to select a single component to develop your project or opt for all components, as you may need them.

Moreover, with the release of Zend Framework 2, each component is available via Pyrus and Composer. Pyrus is a package management and distribution system, and Composer is a tool for dependency management in PHP that allows you to declare the dependent libraries your project needs and installs them in your project for you.

Zend Framework 2 follows a 100 percent object-oriented design principle and makes use of all the new PHP 5.3+ features such as namespaces, late static binding, lambda functions, and closures.

Now, let’s get started on a quick-start project to learn the basics of Zend Framework 2, and be well on our way to building our first Zend Framework MVC application.

Installation

ZF2 requires PHP 5.3.3 or higher, so make sure you have the latest version of PHP.

We need a Windows-based PC, and we will be using XAMPP (http://www.apachefriends.org/en/xampp.html) for our development setup. I have installed XAMPP on my D: drive, so my web root path for my setup is d:\xampp\htdocs.

Step 1 – downloading Zend Framework

To create a ZF2 project, we will need two things: the framework itself and a skeleton application. Download both Zend Framework and the skeleton application from http://framework.zend.com/downloads/latest and https://github.com/zendframework/ZendSkeletonApplication, respectively.

Step 2 – unzipping the skeleton application

Now put the skeleton application that you have just downloaded into the web root directory (d:\xampp\htdocs) and unzip it. Name the directory address-book as we are going to create a very small address book application, or you can name it anything you want your project name to be. When you unzip the skeleton application, it looks similar to the following screenshot:

Step 3 – knowing the directories

Inside the module directory, there is a default module called Application. Inside the vendor directory, there is an empty directory called ZF2. This directory is for the Zend Framework library.

Unzip the Zend Framework that you have downloaded, and copy the library folder from the unzipped folder to the vendor\ZF2 directory.

Step 4 – welcome to Zend Framework 2

Now, in your browser, type: http://localhost/address-book/public. It should show a screen as shown in the following screenshot. If you see the same screen, it means you have created the project successfully.

And that’s it

By this point, you should have a working Zend Framework, and you are free to play around and discover more about it.

Summary

In this article we will learned what is Zend Framework and will also learn how to install it on Windows PC.

Resources for Article:


Further resources on this subject:


Books to Consider

comments powered by Disqus
X

An Introduction to 3D Printing

Explore the future of manufacturing and design  - read our guide to 3d printing for free