The Zend Framework has become one of the most popular frameworks recently. You know that the PHP is an object oriented language and it has become very popular. The PHP stands at the top of the dominant languages. It was installed on most UNIX and Linux based web servers. And if you were a programmer, it was easy to get a hosting account that would let you use it. You can easily communicate it Java, J2EE, Perl languages.
Some features of Zend Framework:
- This is based on PHP language
- This is object oriented Language
- Uses the MVC pattern
- Have open source contributor
Zend is a PHP based framework. Recently, web development has become a very bloodthirsty arena for programming languages and by using the framework, user can do various kinds of activities. As a result, there has been an excess of options for programmers to choose from. Most of the time, a significant amount of time can be spent on searching for tools to speed up development instead of recreating from scratch. This writing is aimed at PHP developers who are looking to learn more about how to acquire knowledge of Zend based framework. This is not a comparative list of all PHP frameworks, as there are many new options like CakePHP and Symphony to name two. Zend framework seems to fit nicely with my requirements and it may not too long time to become familiar with this.
If we want to work with Zend Framework, this has the following requirements:
- PHP 5.2.4 or higher version than that
- A web based server supporting mod_rewrite or similar functionality.
I have assumed that you are running the PHP 5.2.3 or higher with the Apache web server then your Apache installation must have the mod_rewrite extension installed and configured. This time, you must also ensure that Apache is configured to support .Htaccess files.
This is normally done by changing the setting:
Listing 1: Changing settings
If you want, you can download the zip Zend framework from any website. The Zend Framework is supplied with a new command line tool.
Zend tool for window:
- Now create a new directory in Program Files that is called ZendFrameworkCli
- Click on the downloaded archive file, ZendFramework-1.8.4PL1-minimal.zi
- This time copy the bin and library folders from within the Zend Framework-1.7. 4PL1-minimal.zip
- Folder window to the C:\Program Files\ZendFrameworkCli folder. You will get two sub folders: bin and library within it.
- Now you add the bin to the path of:
- Within the Control Panel find out the System section.
- Choose Advanced and then press the Environment Variables button within it.
- In the “System variables” list and find the Path variable and double click on it. Page
- This time adds; C:\Program Files\ZendFrameworkCli\bin to the end of the input box and press okay.
By this way you will able to configure the Zend framework on your system and able to enjoy the great feature of it.
Getting our application:
We are going to develop a normal inventory management system for displaying our CD album. The main page will list our collection and permit us to add, edit and remove CDs. We are going to store our list in a database with a very simple table schema like this:
Figure 1: Table Schema
Creating the project:
Now you open Terminal or Command Prompt and type and change directory to the root of your web server using the CD command prompt. You need to make ensure that you have permissions to create files in this directory and that the web server has gotten the permissions. Type:
zf create project zf-tutorial
The ZF apparatus will create a directory called zf-tutorial and populate it with the recommended directory Structure.
Figure 2: Zend project file system
The presented application/ directory is where the source code for this website stands. We have separate directories for the replica, view and controller records of our application. Here, the public/ directory is the public-facing root of the website and that means that the URL to get to the application will be http://localhost/zf-tutorial/public/. This is so that most of the application files are not accessible directly by the server and so on.
For example, you could create a virtual host called zf-tutorial.localhost that looked like that one:
Listing 2: Create virtual host
Copy the library/Zend/ directory from downloaded archive file (ZendFramework-1. 9.0. zip) into your self-tutoring and library/, so that your zf-tutorial/library/ contains a sub-directory called Zend/.
The Zend Framework controller uses the Front Controller design model and routes all requests through a single index.php file. This formant able to ensure that the environment is set up correctly for running the application (identified as bootstrapping). We reach this using an .Htaccess file in the zf-tutorial/public address list that is generated for us by Zend_Tool which redirect all requests to public/index.php which is also created by Zend_Tool. This is a quite easy job to change the formation of it. The index.php file is the entry point of our application and is used to create an instance of Zend_Application to initialise our application and then run it. This file also defines two constants: APPLICATION_PATH and request_ENV which define the path to the application/ directory and the environment or mode of the request. The generated .hatches file sets it to develop.
The Zend_Application starts at the beginning of the server. It starts up when the component is used to start up the application and is configured to use directives in the configuration file: application/configs/application.ini. This file is also auto-generated for us .The Bootstrap class that extends Zend_Application_Bootstrap_Bootstrap is provided in function/Boostrap.php which can be used to execute any specific startup code required.
Listing 3: Bootstrap class
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
protected function _initAutoload()
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH));
By using this way we will able to run and configure the Zend framework. This framework helps us start any PHP project. Recently PHP offers object oriented facilities. That helps a lot to the programmer with vast development of the project. You know that Zend is a lightweight framework that helps a lot to integrate PHP language quite easily within it.
This is all for this article. See you next time.