Few months back, we read about starting a Zend framework based project. Today we are taking a second look at the Zend application architecture. Zend framework is also an implementation of MVC pattern. Though Zend framework stands out among the various PHP frameworks, the application structure remains similar to other MVC based frameworks like CodeIgniter. By default, every Zend framework project has four main directories –
application, library, public and tests. Zend framework allows the developers to overwrite the names of these directories.
Zend Application Directory
Similar to CodeIgniter, the Zend
application directory is the place where the project files reside. This directory stores the models, controllers and views of the application. The application directory contains the project code organized into four default folders named,
configs, models, controllers and views. For large applications, there are Zend modules to break the controllers, models and views into smaller and manageable groups.
In addition to the four directories, the application directory also contains the
Bootstrap.php file. This file initializes project specific resources, components and data. When a request is made to the application, the web server calls the
By default, the
Bootstrap.php initializes the Zend Front Controller, which initializes the request environment and routes the incoming requests. The ZF front controller also dispatches the discovered actions, aggregates the responses and finally, returns the responses when the process is complete.
configs directory contains the
application.ini file. This file stores the configuration settings of the Zend framework application. This includes the PHP settings like error reporting and the bootstrap settings and application resource parameters.
Zend Library Directory
library directory holds all the classes that support a Zend framework application. This includes the Zend framework components and custom components which are out of the scope of the application. The Zend directory inside the library directory contains the Zend framework files.
However, you may place the Zend framework files in any folder defined in the PHP include path.
Zend Public Directory
By default, the public directory contains an
index.php file. This is the front controller of the application. This file is responsible for handling every user request for any page of the application.
Zend Tests Directory
This directory contains the test suite for the application. These tests could be hand-written or framework based. Among the supported testing frameworks are PHPUnit tests and Selenium-RC.
In addition to four top level directories, a Zend project skeleton also contains a
.zfproject.xml. This file gets generated and modified by the Zend command line tool. This file doesn’t require any manual modification but it should be retained in the directory structure. You can continue to use the command line tool, if you have this file in the project structure.
The commonly recommended structure is not the only way to structure your Zend framework application. The Zend framework application can be developed and distributed as a module pluggable for another website. Such an application may follow different architecture.