ⓘ Zend Framework


ⓘ Zend Framework

Zend Framework is an open source, object-oriented web application framework implemented in PHP 7 and licensed under the New BSD License. The framework is basically a collection of professional PHP-based packages. The framework uses various packages by the use of Composer as part of its package dependency managers; some of them are PHPUnit for testing all packages, Travis CI for continuous Integration Services. Zend Framework provides to users a support of the Model View Controller in combination with Front Controller solution. MVC implementation in Zend Framework has five main areas. The router and dispatcher functions to decide which controller to run based on data from URL, and controller functions in combination with the model and view to develop and create the final web page.

On 17 April 2019 it was announced that the framework is transitioning into an open source project hosted by the Linux Foundation to be known as Laminas.


1. License

Zend Framework is licensed under the Open Source Initiative OSI-approved New BSD License. For ZFv1 all code contributors must sign a Contributor License Agreement CLA based on the Apache Software Foundation’s CLA. The licensing and contribution policies were established to prevent intellectual property issues for commercial ZF users, according to Zends Andi Gutmans. ZF2 and later is CLA free. There is also a longterm support available for the framework long term support or LTS for a total duration of 3 years.


2. Zend Framework components and versioning

Starting with Zend Framework version 2.5, components are split into independently versioned packages and zendframework/zendframework is converted into a Composer meta-package. Framework components introduced after the split are not added to the meta-package.

While zendframework/zendframework meta-package release version remains at 3.0.0, it will instruct Composer to install latest compatible versions of the framework components, as per the semantic versioning. Such that zend-mvc component will be installed at its current version 3.1.1, zend-servicemanager at version 3.3.0 and zend-form at version 2.10.2.

Zend Framework includes following components:


3. Installation

Officially supported install method is via Composer package manager.

Zend Framework provides meta-package that includes 61 component but recommended way is to install required framework components individually. Composer will resolve and install all additional dependencies.

For instance, if you need MVC package, you can install with the following command:

Full list of components is available in Zend Framework documentation.


4. Anatomy of Zend Framework

Zend Framework follows configuration-over-convention approach and does not impose any particular application structure. Skeleton applications for zend-mvc and zend-expressive are available and provide everything necessary to run applications and to serve as a good starting point.


4.1. Anatomy of Zend Framework Recommended MVC application directory structure

ZendSkeletonApplication, skeleton application using Zend Framework MVC layer and module systems, can be installed with:

It will create file structure similar to this:

The config/ directory has application wide configurations. module/ directory contains local modules that are committed along with application. vendor/ contains vendor code and other modules managed independently from the application, content of the folder is normally managed by Composer.

Zend Framework module have only one requirement: Module class exists in a module namespace and is autoloadable. Module class provides configuration and initialization logic to application. Recommended module structure is as follows:

The config/ directory holds module configs, src/ directory contains module source code, as defined in PSR-4 autoloading standard, test/ directory contains unit tests for the module and view/ directory holds view scripts.


5. Creating project structure

Zend framework supports command line input to create structure of directories. We will use command line interface to start creating the directory structure for our project. This will give you complete structural understanding of directories. The interface supports and provides Zend_Tool interface giving a whole host of command functionalities.

  • Windows users type: bin\zf\bat create project
  • Open the command line interface, and change the hellozend directory.
  • Linux/Mac users type: bin\zf.sh create project

This procedure will create Zend Framework project in a your own specified location. After running Zend_Toll it will create the basic application skeleton. This will not only create directory structure but also all the basic elements of the MVC framework. In order to get Apache functionalities the virtual host settings will be as:

The basic directory structure created will be somewhat as mentioned in the aforementioned directory structure of Zend Framework with similar explanation. There is another aspect of Zend-Tool which is automatically initialized during installation is bootstrapping. Here the basic purpose is to initialize the request of page by developer. The main entry here created by Zend Framework is the Index file. Index file provides function to handle user request. This is the main entry point for all requests. Following shows the functionalities.

  • Initialize Zend-Application application: includes Zend-Application and create an instance of it.
  • Call bootstrap method coupled with run method starting MVC.
  • getenv: checks system environment.
  • Application_Env: changes the application behavior depending on various factors such as how the application is used.
  • Application-path: defines the path to application directory

In general Zend-Tool creates many important directory structures. This system is built upon Rapid Application Development technology. As a general rule of support the framework focuses on coding and project structures instead of focusing on smaller parts.

  • Bootstrap file
  • Views
  • Controllers
  • Actions
  • Project directory structure


5.1. Creating project structure Controllers

Controller is the main entry to Zend Framework application. The front controller handler is main hub for accepting requests and running the accurate actions as requested by the commands. The whole process of requesting and reacting is routing and dispatching which basically means calling correct methods in a class which determines the functionality of the code. This is implemented by Zend_Controller_Router_- Interface. The router functionality is to find which actions need to be run and on contrary dispatcher runs those requested actions. The controller in Zend Framework is connected in a diverse array of structural directories, which provides a support to efficient routing. The main entry point and the command controller is the Zend_Controller_Front, this works as a foundation which delegates the work received and sent. The request is shaped and encapsulated with an instance of Zend Controller Request HTTP, as a provider of access to HTTP requests. The HTTP hold all the superglobals of the framework with their relevant paths. Moreover, the controller also provides getParam functions which enables collection of requested variables.


5.2. Creating project structure Actions

Actions are important functionalities. Controllers do not function without Actions. For this purpose we create another method which has action appended in its name and automatically the front controller will recognize it as an action. The Action has init method which shows its private nature and not accessible by anyone. Following commands are run so that Zend_Tool can create action for us. Through the use of standard dispatcher all functions are named after the actions name and followed by word "Action" appended. This leads to controller action class containing methods like indexAction, viewAction, editAction, and deleteAction.

Windows users:

bin\zf.bat create actions about index

Linux and Mac users:

bin/zf.sh create action about index

An example of forms and actions:


5.3. Creating project structure Standard router

Standard router is an important Front Controller tool. Here the main decisions are made in order what module, controller and action are being requested. These are all processed here. The following are defaults structure.

  • Module
  • Controller
  • Actions

The request follows a pattern first information is taken from URL endpoint of HTTP. URI is the end point of the request. URL structure follows as:

The default router code example:


5.4. Creating project structure Utility methods

The Zend Framework also provides some utility methods. Following are some utility methods provided in the framework.

_forward it is used to call action _forward { $action, $controller = null, $module = null, array $params = null } $actions string, action required $controller optional string parameter and is place where controller is in. $module string, has module in which we have the controller. $params array, user parameter

Another method is the redirect utility method. This is the opposite of aforementioned _forward method. _redirect performs HTTP in redirection in creation of a new request. _redirect methods accepts two arguments namely $url, and $options.

Furthermore, Action Helpers are also a way to provide extra functionalities within the framework. Action helpers are useful when there is a need to provide functionality between controllers.

During initialization phase of IndexController and ContactController, viewReader is called and noRender flag is called on the view object. The lack of this process creates an error in our application.


5.5. Creating project structure View directories

Zend Framework provides the view framework to our project and controller and actions are automatically provided to our application. Inside the Zend Framework in view folder we observe the following folders.

  • Helpers
  • Contacts
  • Scripts
  • View
  • index
  • errors

In order to create a view we follow:

View Sample:


6. Sponsor and partners

Zend Technologies, co-founded by PHP core contributors Andi Gutmans and Zeev Suraski, is the corporate sponsor of Zend Framework. Technology partners include IBM, Google, Microsoft, Adobe Systems, and StrikeIron.


7. Features

Zend Framework features include:

  • Extensible MVC implementation supporting layouts and PHP-based templates by default
  • Flexible caching sub-system with support for many types of backends, such as memory or a file system.
  • Use-at-will architecture with loosely coupled components and minimal interdependencies
  • All components are fully object-oriented PHP 5 and are E_STRICT compliant, which helps in the development of building tests and writing codes in a bug-free and crash-proof application manner.
  • With the help of remote procedure call RPC and RESTRepresentational State Transfer services, Zend Apigility helps developers to create APIs, authentication of APIs, documentation of APIs, Easy Modification
  • Email composition and delivery, retrieval via mbox, Maildir, POP3 and IMAP4
  • Support for multiple database systems and vendors, including MariaDB, MySQL, Oracle, IBM DB2, Microsoft SQL Server, PostgreSQL, SQLite, and Informix Dynamic Server

8. Development of applications

Zend Framework applications can run on any PHP stack that fulfills the technical requirements. Zend Technologies provides a PHP stack, Zend Server or Zend Server Community Edition, which is advertised to be optimized for running Zend Framework applications. Zend Server includes Zend Framework in its installers, along with PHP and all required extensions. According to Zend Technologies, Zend Server provides improved performance for PHP and especially Zend Framework applications through opcode acceleration and several caching capabilities, and includes application monitoring and diagnostics facilities. Zend Studio is an IDE that includes features specifically to integrate with Zend Framework. It provides an MVC view, MVC code generation based on Zend_Tool a component of the Zend Framework, a code formatter, code completion, parameter assist, and more. Zend Studio is not free software, whereas the Zend Framework and Zend Server Community Edition are free. Zend Server is compatible with common debugging tools such as Xdebug. Other developers may want to use a different PHP stack and another IDE such as Eclipse PDT which works well together with Zend Server. A pre configured, free version of Eclipse PDT with Zend Debug is available on the Zend web site.


9. Code, documentation, and test standards

Code contributions to Zend Framework are subject to rigorous code, documentation, and test standards. All code must meet ZFs coding standards and unit tests must reach 80% code coverage before the corresponding code may be moved to the release branch.


10. Simple cloud API

On September 22, 2009, Zend Technologies announced that it would be working with technology partners including Microsoft, IBM, Rackspace, Nirvanix, and GoGrid along with the Zend Framework community to develop a common API to cloud application services called the Simple Cloud API. This project is part of Zend Framework and will be hosted on the Zend Framework website, but a separate site called simplecloud.org has been launched to discuss and download the most current versions of the API.The Simple Cloud API and several Cloud Services are included in Zend Framework. The adapters to popular cloud services have reached production quality.


11. Hello World: file by file

In order to create Hello World program, there are multiple steps including:

  • First create four files within the directory structure. These files are bootstrap file, an Apache Control file.htaccess, a controller file and a view controller for the view.
  • Second a copy of Zend Framework need to be developed. With the growth of complexity, additional code is required which will provide the functionality and that is relative small and focuses on the benefits of MVC system. Regarding the process in more detail, the bootstrap file is initialization in one form or another.

Next it needs to be ensured the environment is correct and that there are no errors, followed by setting date and time for tracking functionality. In order to set up date and time many procedures can be followed; for example the method data_default_timezone_set can get called and Zend assumes that default directory will include the phd path. The Zend Framework does not depend on any specific file, but helper classes are helpful in this case. Following are some examples:

  • Following this the underscores are converted into directory-specific structures. As a result, the code lines Zend_Loader loadClassZend_Controller_Front; and include_once Zend/Controller/Front.php; show similar results.
  • Zend_Loader loadClass the main purpose here is to correct file for the supplied class name.
  • Zend_Debug dump functions in terms of debugging information and is focused on formatted var_dump output. Finally the bootstrap runs the front controller and initializes it. The design pattern used by Zend_Controller_Front is the Singleton design and getInstance is used to get the single instance.

12. Current development

Zend Framework 3.0 was released on June 28, 2016. It includes new components like a JSON RPC server, a XML to JSON converter, PSR-7 functionality, and compatibility with PHP 7. Zend Framework 3.0 runs up to 4 times faster than Zend Framework 2, and the packages have been decoupled to allow for greater reuse. The contributors of Zend Framework are actively encouraging the use of Zend Framework version 3.x. The stated end of life for Zend Framework 1 is 2016-09-28, and for Zend Framework 2 is 2018-03-31. The first development release of Zend Framework 2.0 was released on August 6, 2010. Changes made in this release were the removal of require_once statements, migration to PHP 5.3 namespaces, a refactored test suite, a rewritten Zend\Session, and the addition of the new Zend\Stdlib. The second development release was on November 3, 2010. The first stable release of Zend Framework 2.0 was released 5 September 2012.