In the true spirit of the open source movement, we decided to build our sample application using Web Development Framework. In software development, a framework is defined as a support structure in which other software projects can be organized and developed. A framework might include support programs, code libraries, a scripting language, or other software to develop and glue together the different components of a software project. Here are few examples of application development framework. You can find more than 20 frameworks on the Web, written in PHP alone:
A framework provides a skeleton on which you can build a software solution using different components. A framework also allows developers to focus on business logic and not the tedious part of software integration. Some people may argue that using a framework can add code bloat (unnecessary long and slow code) and also usually involves a steep learning curve. But the increasing popularity of PHP for database-driven Web applications is enough good reason for us to consider use of a framework for PHP development in this book. We decided to use an open source framework called Zend Framework for PHP. We divide this chapter into two parts.
Part I gives an overview of PHP application development using Zend Framework preview release, followed by a sample database application using Zend DB Adapter for access to DB2 Express-C.
Part II focuses on development of a PHP application using the new XCS (XML Content Store) technology, which is part of Zend Framework. This section is also followed by a sample, Social Network Application, which you can build and deploy very quickly using XCS and new DB2 Express-C XML pureXML technology.
Again, in the spirit of open source, we decided to use the Eclipse application development environment (with a PHP plug-in) to write PHP code. Zend also offers a trial version of its development environment called Zend Studio, but we chose Eclipse because it is free and easy to use.
Zend Framework overview
The PHP language has been around for a long time, but it was not adopted in large enterprise environments. It began as a scripting language and was considered as a glue to integrate processes quickly and flexibly. PHP is also popular for building database driven Web applications. With the development of application development frameworks, PHP is well prepared for enterprise applications because it should be capable of integrating components and services in the enterprise. Zend Framework is this type of framework developed by Zend and its partners for designing PHP5-based enterprise grade Web applications quickly. The framework is based on MVC (Model-View-Controller) architecture. The primary benefits of using a MVC architecture for your next Web application are:
Zend Framework aims to provide an architecture for developing entire Web applications with no other library dependencies. Zend and its partner companies are committed to actively develop and support the framework code. Zend also supports a community Wiki page as a developer zone. This Web site contains recent committed code and also issues problem (bug) tracking and other developer resources. Zend Framework also enforces a strict PHP coding standard to maintain uniformity among the framework and application code.
The core of Zend Framework is the Zend_Controller. The Zend_Controller is designed to be light weight, modular, and extensible. The Zend_Controller workflow is implemented by several components. Understanding the underpinnings of all components is not necessary to build an application, but knowing how they work and interact with each other is definitely helpful:
The dispatcher process takes the dispatcher token, finds the appropriate controller, instantiates the controller class, and finally runs the action method in that controller object. In summary, this is how Zend_Controller works:
We discuss more about these objects whenever needed, but for now, let us go through the setup required for using Zend Framework.
Setting up Zend Framework
Setting up Zend Framework is quite easy. This section assumes that you have PHP up and running with some supported Web server in your environment. Our example uses:
One very important goal of any framework is to simplify the common code structure. We recommend this directory structure:
zframework directory structure
Note: Zend Framework is currently released as preview 0.1.4 and at the time of writing this book, this was the release available to use. Check the Web site and use the latest version as it becomes available. You can also connect to their Subversion Repository for anonymous checkout of the latest code and report bugs. Zend Framework Developer Web site has plenty of information for PHP developer.
One important goal of modern Web applications (Web sites) is to have clean URIs (without any attached query parameters). This kind of URI rewrite support is required from Web server. Zend Framework currently depends on Apache’s mod_rewrite module to redirect all requests to a single file called index.php that resides in Web server’s document root directory and contains the bootstrap function (in this case, Zend_Controller_Front). The configuration of the server requires a few steps:
Note: Zend is currently looking for a solution, which does not require mod_rewrite, for the future. There is a good chance that the final release of this framework will not require you to perform this setup.
.htaccess fileRewriteEngine on
The above file redirects all requests not containing one of the previous file exten- sions to index.php bootstrap file. Alternatively, you can modify httpd.conf also for the rewrite rules, but that requires you to restart the Web server. Adding to .htaccess file does not require you to restart Web server. You also need to include the include_path to the framework library directory (zframework/lib). You can add this to the php.ini file or simply add it into .htaccess as shown below
The Zend class (zend.php) contains static methods that are used by many classes. This is the only class you need to include manually, so we add it to our bootstrap file index.php.
After adding it to the bootstrap file, we now have access to all static methods. You can load other classes with the loadClass() method. For example, to load Zend_ Controller_ Front:
Note: This is the only php file required to exist within the Web server document root directory. Also for security reasons, it makes sense not to store the php files in the directories that are accessible by the Web server.
Now, to understand the framework flow and make sure setup is working, let us do this exercise:
Let us discuss the different parts here:
There is another useful method called noRouteAction(). You can specify a _redirect() call to redirect the requests for nonexistent pages to the desired page. if you add the noRouteAction() method to the IndexController.php, it redirects our request of redbook/toc to the main page.
c. Now, let us create the RedbookController.php as shown below. We have an index Action() method for non-existent action request and tocAction() for our redbook/toc request.
Now, our request for http://localhost/redbook/toc should echo the text TOC of this book follows. Notice there is another function, __call(), to handle undefined actions such as redbook/appendix.
You can see that the controller/action mechanism allows you to have friendly URIs for your Web application and also allows you to organize them properly. This completes our basic test of mod_rewrite and the framework setup. We discuss other controller objects in detail when we build our sample application but for now we move on with the Eclipse enviro- nment setup.
IBM DB2 Related Interview Questions
|IBM Websphere Interview Questions||IBM-REXX Interview Questions|
|IBM Cognos Interview Questions||IBM DB2 Interview Questions|
|J2EE Interview Questions||COBOL Interview Questions|
|IBM-JCL Interview Questions||DB2 Using SQL Interview Questions|
|IBM WAS Administration Interview Questions||IBM WebSphere Administration Interview Questions|
|Database Administration Interview Questions||DB2 SQL Programming Interview Questions|
|Mainframe DB2 Interview Questions|
IBM DB2 Related Practice Tests
|IBM Websphere Practice Tests||IBM Cognos Practice Tests|
|IBM DB2 Practice Tests||J2EE Practice Tests|
|COBOL Practice Tests||IBM-JCL Practice Tests|
|DB2 Using SQL Practice Tests||IBM WAS Administration Practice Tests|
|Database Administration Practice Tests||DB2 SQL Programming Practice Tests|
Ibm Db2 Tutorial
Db2 Application Development Overview
Application Development With Db2 Purexml
Application Development With Php
Application Development With C/c++
Application Development With Java
Application Development With .net
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.