Zend Framework 2 - Application Development Review

January 19, 2015


                       Zend Framework has come a long way from Zend Framework 1 to the current version Zend Framework 2; Zend Framework 2 is a complete re-write from the ground, it has been built with flexible and good pratices. A lot of its component have been modified to ensure it fits into it's current goal, This book focuses on using the framework to create a social network, using Zend Framework 2 components and patterns to illustrate to users ways; application can be built on the framework.




Chapter 1: Let’s Build a Social Network


            Chapter 1 introduces the Zend Framework and explains why users should adopt the framework, while giving an historical background of the Zend Framework 1, it also deals with the task at hand, it envisions the project of building a social network using an API centric approach, so as to expose its functions and features to numerous clients. It also gives reasons for the choice of the pattern and the features of the social network that will be created using the Zend Framework 2.0.


Chapter 2: Setting up the Environment

            Chapter 2 focuses on a new tool called “Vagrant” which allows you to customize your Virtual Machine per projects, it simply involves running a script which pre-configures your virtual machine for the project.


Chapter 3: Scratching the Surface of Zend Framework 2

            Chapter 3 touches the core aspect of Zend Framework 2, it touches on the components which Zend Framework 2 is built upon; it's important to highlight that understanding this chapter is a big step towards mastering the framework. The following important topics are covered in this chapter:

·         The Configuration Array: The Array Configuration responsible for  bootstrapping the application.

·         PSR-0 and Autoloaders: Mapping of PHP classes to Physical files and how to load them.

·         Service Manager:  The core concept of this is Service Locator Pattern, it retrieves other objects for use and stores objects.

·         Event Manager:  This allows the framework to have Event-driven architecture, it deals mostly with Publishing and Subscribing of events.

·         Module Manager:  An important feature that allows the framework to be Modular and decoupled, the core principle behind this is to further allow reusability among developers.

·         Request Object:  An API built with as a wrapper around the $_REQUEST in PHP, it exposes useful methods and properties on the $_REQUEST environment variable.

·         Router: explains how the router the URL  and dispatches it to the relevant controller, it also breaks down several available routers e.g. SimpleRouteStack, TreeRouteStack e.t.c

·         Controller  Plugins:  This allows  you to use a plugin inside a controller , an example of such is the FlashMessenger  plugin.

·         AbstractRestfulController:  this  differs from the AbstractController which handles the controller and its action, in this class it maps all its actions to REST methods.

·         Response Object: Just as the request object, the response objects is a wrapper around the HTTP response data.


            The chapter closes with creating a working example of from the request to the response which is returned in a view, this chapter gives you a feel of how the basic operation of the framework works.


Chapter 4: The First Request/Response – Building the User Wall

        This  section focuses on building the user wall of the social network platform, it explains getting data from the database and displaying them on the frontend. It also touches on the AbstractRestfulController which will be used to create an API which will expose the data for the social network.  In order to achieve this feat it covers the following  topics:

·         Working with Database: Using Vagrant to connect to MySql and setting up sample data.

a)     Zend\Db\TableGateway

b)     Zend\Db\Adapter

c)      Zend\Db\RowGateway

·         Setting up the connection

·         ViewManager Configuration

The chapter dives into various topics which such as the module configuration and setting the response to JSON to be consumed by applications.




Chapter 5: Handling Text Content - Posting Text

            All Social networks involves posting data, this explains using Zend Framework to handle this process by creating the form with the Zend\Form class and Zend\Input Filter which handles the validation on the server side, and ways to also secure yourself using the CSRF, at the end of this chapter users will gain the knowledge of creating forms and storing them in the databases, and also Form Validations in ZF2.


Chapter 6: Working With images - Publishing Images

This covers using the Zend\Form to handle file uploads, and adding validation for the files, it also further dives into manipulating the image upon uploading the file. This chapter will expose you with relevant filters to use while handling Files and Zend\Form\Elements to use to handle file uploads.


Chapter 7: Dealing with URL - Posting Links

            In this chapter the user will get the opportunity to use the Zend\Http\Client class to fetch the website information and title, a feature similar to Facebook posting. it also shows how to create a customer Validator to be used by the Zend\Form.


Chapter 8: Dealing with Spam - Akismet to the rescue

            Just like every social networks and platform, spams are a reckon to deal with, this chapter equips you with the ZendService class;  this class deals with interacting with third party APIs by simply using the methods of each service. You will create a Custom Validator around the Akismet API to ascertain if the comment is a spam. After this chapter you will gain more knowledge about the ZendService and some useful components such as the Zend\Crypt\Password.


Chapter 9:Let's Read Feeds - A News Reader

            The introduces various topics such as CLI (Command Line Interface, CronJobs, Feeds), this chapter will inform the user on how to create cli applications, and running them via cronjob (a Unix program) also modifying to the router to dispatch the appropriate controllers and action for each url.  This chapter will expose you to creating scheduled tasks, developing cli applications in Zend Framework 2,Zend\Feeds  and other important classes necessary to achieve this feat.


Chapter 10: Sign Up

            Using the previous knowledge on Zend\Form and Zend\Filters, the developer creates the sign-up form from which users fill to use the social network, this chapter will dig deep into using additional Filters and Validations supported by Zend Framework to achieve the solution.


Chapter 11: Log In

            you will learn a lot of concept such as authentication of user using the AuthenticationService. The chapter explains the use of AuthenticationService with the Authentication Adapter which checks the credentials against a data-source (MySql Database) and permission of the application using the ACL (Access Control List).


Chapter 12: Sending an Email

            This chapter focuses on the popular Zend component Zend\Mail, however unlike traditional form of sending images, the chapter reveals numerous methodology of sending mails and the necessary classes to adopt.  The author goes further to explain the role of the class PhpRenderer in association with the email templates, towards the ending of the chapter; the author gives suggestion of features to be implemented, in order test the user on his knowledge about the framework(Zend Framework 2).


Chapter 13: OAuth 2.0 Protocol Securing our API

            Chapter 13 illustrates the procedures involved in securing the API of the social network, as to avoid being abused due to the fact of it being exposes, the chapter shows the use of Oauth 2.0 to secure the API, this chapter requires subsequent reading; as it uses both the ServiceManager and EventManager  to handle the process. a bit is mentioned on the session class Zend\Session\Container.



            Zend Framework 2 Application Development  is a straightforward that attempts to cover the rudiments of Zend Framework 2 with few words. The book is really interesting because it covers the core concept on which Zend Framework 2 was built upon. Zend Framework 2 Application will gives the user a sense of understanding about the framework equipping the user to have a general knowledge; from which the user would be able to move on and tackle more complex issues. However my personal opinion is that users might need to read this subsequently to fully grasp the framework, as the learning curve involved is quite high.


About  the Author

Christopher Valles is a Software Engineer from Barcelona, Spain, currently based in London, UK. He started developing when he was seven using a Vtech kid laptop that was strangely shipped with a simple version of the BASIC programming language. Since then, he has explored more than 16 different programming languages ranging from Assembler to PHP, Python, and GO. The sectors where Chris has worked ranges from adult content websites and payment processors to social networks and the gaming industry. Presently, he's working as a Software Engineer at Hailo Networks, Ltd.

Post Comment