Sample Web application - IBM DB2

In order to showcase the features of DB2 Express-C, PHP, and the brand new Zend Framework, we built a couple of sample Web-based database applications. The first application is a “Movie of the week” survey application, where using a simple Web interface, you can add a movie name to the database and vote for the movie of the week. Your suggestion for a new name or your vote instantly updates the Web site. The application demonstrates the framework’s simplistic MVC model to build database driven applications using Zend db adapters.

While designing any Web-based application, we start by designing interfaces. A Web application is a collection of Web pages where each page is a unique URL. This simple survey application consists of two URLs:

  • /index/vote
  • /add/movie

You need to think of these URLs in terms of controller/action. The IndexController fetches the existing movies’ names and the respective votes from the database and AddController handles adding new suggestions and updating votes. You can have multiple presentation layers created in the views directory, but for simplicity, we have a single presentation layer vote.php which manipulates and presents the survey results.

It lists belowthe files created for our movie example. You can download the complete zip file from the redbook Web site.

Files for example application

Files for example application

Let us look at the IndexController.php first. We have intentionally left indexAction method untouched and created a voteAction() method. As a result of this, the main URL to launch this application is:


You can alternatively not have the voteAction() method and move the code inside the index Action method(). In that case, you launch the application with this URL:



We would like to display the survey results currently in the database on the main page. To do that, we created a voteAction() method, where we initialized the database and view registries. Then, we call a database method db showVote() which queries the movie_names table and gets the sum of the votes. Then, we used the sum to create the percentage of the votes and called another database method db showData() to get the movie names. Finally, we rendered the page to display the movie names along with the percentage of votes. We also allowed users to add a new movie name and vote for the new suggestions. We handled the database insert for the new movie suggestion in AddController.php. We created a movieAction(), which uses dbAdapter method insert() to add movie into the db2 table. The code in Example shows AddController.php. The movieAction() method calls database functions to perform insertions and updates.


Note: indexAction() in the controllers other than indexController should never be called. Because you do not have any control over the user being creative and modifying the URL to access anything, you should always redirect the URL appropriately. Also, in order to support dynamic actions, such as add/123, you must implement __call() functions.

Integrating with databases: Zend_Db_Adapter
Zend_Db_Adapter is the database API abstraction layer for the Zend Framework. You can use same Zend_Db_Adapter to connect to and work with many databases, including MySQL, DB2, Sybase, SQL Server, and others. You first need to create an instance of your database server. The code shown in below how to create the instance of DB2 database.

Creating instance of DB2 database using Zend_Db_Adapter

You can ignore the host and port parameters if the DB2 server is local to the framework. Once a DB2 instance is created, it can be passed to the database class being initialized. For our sample application, we create a Database class database.php. The code shown in Example creates an instance of the database class and makes our database object available through the registry variable. A registry is a Zend framework object that can save information (for example, a database connection or view) and be made available in your Web application when required.

Registering database

For a database driven application, the database registration code as shown in Example should be placed in the bootstrap file located under framework’s www directory. Once registered, the database object can be accessed anywhere just by making it available through the registry:

Now, our simple database class implements the utility methods to add, update, and query the movie database as shown in below

Database class

The important part of the database class in Example is the constructor function, which expects the instance of the db adapter class. It assumes that the database and tables exist already. We have created our movie table manually, but you can certainly construct the CREATE TABLE statement and use framework’s direct query() function to create the table for the first time.

As you can see in the Database.php we have used the fetchRow() function in the show Vote() method and the fetchAll() function in the showData() method. Zend Framework provides the fetch*() series of methods, which executes the supplied query and process result. You can also pass the placeholder and an array of bind values to be quoted and replaced into the statement for you. These are the fetch() methods available for you to use:

  • fetchAll()
  • fetchAssoc()
  • fetchCol()
  • fetchOne()
  • ifetchPairs()
  • fetchRow()

The framework user manual shows sample code snippets on their usage. In addition to the convenience methods we have already discussed, the framework also provides some tools, which help you construct SQL statements and manipulate database objects:

  • Zend_Db_Select
  • This tool provides built-in functions to construct the SELECT statement with various clauses. see below

    Constructing SELECT using Zend_Db_Select

  • Zend_Db_Table
  • It is a Zend_Db_Adapter class, which lets you examine the table schema and then aids you in manipulating and fetching rows from the table. You need to create a class with the same name as the table name (camelized), which extends Zend_Db_Table class. By default, the camelized class name maps to the underscored table name, but you can also override this by redefining the $_name property.

    Note: The database components of the Zend Framework are relatively unstable and new features and functionalities are being added. Some of the database object features might not work in the preview release, but the good news is that you are free to manipulate the code and design the function your own way. For example, we have used the adapter’s insert() method to add movie names to the database. Alternatively, your application can construct the INSERT statement and use adapter’s direct query() function to execute and achieve the same result. The actual implementation of these API methods available for your use are in Db2.php located under the lib/Zend/Db/Adapter directory.

Integrating the components
To put this all together, we create database.php in lib directory. The __autoload() function in our bootstrap file, www/index.php, is able to load it when needed. The bootstrap file also instantiates $db and $view and loads them in registry variables. Finally, we create a template to display the result. In the case of our small survey application, we create an HTML template embedded with some php code. Typically, we recommend that you create different templates for different URLs supported by the application, and one index.php exists as an initial template. vote.php is our only template and displays both initial movie information and modified survey results, because this is the most appropriate way of displaying results for this application. The code in below shows the app/ view /vote. php.


With everything in place, you can see that the presentation layer is separate from the business logic layer, and adding more business logic and presentation is extremely easy. The code looks clean; it is flexible and extensible. The end result is the Web site shown in below

Movie of the Week initial page

Movie of the Week initial page

Zend framework: XCS
One of the major advantages of using a Web framework is that it provides the abstraction to the database layer to create a database driven Web site easily. The developer can concentrate on the behavior of data rather than the details of database access and manipulation. With the amount of proliferation of XML data over the Web and elsewhere, there is a need to abstract the persistence access of XML data. DB2 Express-C V9 provides pureXML storage to store and manage XML data in its native structure. XML Content Store (XCS) has been created to help simplify the development of XML-centric Web applications. XCS is an incubator technology in Zend Framework and provides both a persistence data access layer as well as an API for managing XML data easily.

In this section, we provide an architectural overview of the XCS. We describe each of the components that makes up the XCS, and we explain how they work together. Below it illustrates the XCS architecture.

XCS architecture overview

XCS architecture overview

XMLContent (Zend_Db_Xml_Content)
As a developer, you can encounter XML data in many forms, such as Web services messages, RSS/Atom feeds, and configuration files. Once you decide that this XML data needs to be saved somewhere, we can assume several things about this data:

  • First, we need a way to uniquely identify it, so that once it is saved, it can easily be programmatically found and retrieved. The unique name can be a numeric ID or a user-provided name.
  • The second assumption is that the XML data will be stored “as is”. It will not be modified or changed in any way. Any modifications that are required will be made by the application outside of the XCS. Internally, the XML data is stored as a DOM document, but an application is free to access the data as a file stream, string, or several other convenient access methods which can or cannot be implementation-dependent.
  • Third, the capability is provided to add additional metadata about the XML data that is saved. For example, if the XML data is a blog entry, perhaps the application would care to know the date and title of the entry, or the hostname where the entry originated. This metadata is saved in an about property and is also XML.
  • Finally, often XML data is accompanied by binary data, such as .jpeg, .pdf, or .doc files. An attachment property associates this binary data with the XML data. In the current implementation of Zend_Db_Xml_Content, the attachment property can contain either zero or at most one item, though optionally, a future version can contain any number of items.

These properties of the XML data are encapsulated in an object called Zend_Db_Xml_Content. Zend_ Db_ Xml_ Content objects are the fundamental components of the XCS because they are the XCS representation of XML data. As we will see, the Zend_Db_Xml_ContentStore component needs to know about the persistence technology (for example, a relational database) and how to access it, but Zend_Db_Xml_Content objects do not need to know anything about it.

Zend_Db_Xml_ContentStore is an abstract class that represents a repository of XML documents. It is responsible for updating the data source based on changes made to a Zend_Db_Xml_Content object in the repository as well as retrieving Zend_Db_Xml_Content objects from the data source based on search or ID criteria. A data source is defined very generally as the persistence layer where the XML data is saved. It can be a relational database, an XML database, or a file system, and it stores the XML data in its own format. When an Zend_Db_Xml_ContentStore object is instantiated, it receives a connection handle, which describes in a meaningful way what the data source is. Below it shows how to create an XML ContentStore using DB2 dbAdapter.

Creating an XML ContentStore

XML ContentStore $xcs has been given a name, so $xcs only manages XML data related to specific application blogs. Other content stores can be created to manage other types of XML data.

Zend_Db_Xml_ContentStore knows how to access the persistence layer to perform Create, Read, Update, and Delete (CRUD) operations and abstracts these operations by using convenience methods. For example, if the persistence layer is a relational database, a call to the method insert() builds an appropriate SQL insert statement based on the structure of the underlying tables used and the content of the Zend_Db_Xml_Content object. It connects to the database and executes the statement. Other CRUD methods work in a similar fashion and include update(), delete(), deleteById(), and selectAll(). Below shows how to save XML data in the XML ContentStore.

Saving XML data in the XML ContentStore

Similar functions exist for update and delete. In addition, Zend_Db_Xml_ContentStore also contains a simple search facility that retrieves Zend_ Db_ Xml_ Content by its ID or by searching within the XML data or the metadata in Zend_ Db_Xml _Content. The search on XML data is done using XPath expressions. Some of these methods are find() and find ById().

The class XMLContentStoreDB2 is implemented using the DB2 adapter which in turn uses the ibm_db2 CLI driver. For example, to insert, the application gives the XCS an XML Content object and the XMLContentStoreDB2 takes care of the underlying details. Because DB2 9 supports a native XML data type, one Zend_Db_Xml_ContentStore_DB2 object maps to one table with four columns named as ID, DATA, ABOUT, and ATTACHMENT. The table columns are defined as follows:

  • ID is a unique integer and is used as the primary key of the table.
  • DATA is defined as an XML column.
  • ABOUT is defined as an XML column.
  • ATTACHMENT is defined as a BLOB column.

Using DB2, each row in the table represents one Zend_Db_Xml_XmlContent object.

It is possible that a search returns one Zend_Db_Xml_Content or a set of Zend_ Db_ Xml_ Content objects. In the case where a set is returned, the Zend_ Db_ Xml_ XmlIterator class is used to iterate over the set of XML documents that meets the search criteria. Zend_Db_Xml_XmlIterator implements the Iterator interface so it knows several essential things about the set of Zend_Db_Xml_Content objects over which it is iterating. These include its current location in the set, how to retrieve the next object in the set, how to go back to the beginning of the set, and when it has reached the last item in the set. This allows the developer to assign behavior on the XML data at each iteration without having to worry about the details of loop control. An example of XMLIterator is shown along with the example of other utility functions in the next section.

Zend_Db_Xml_XmlUtil is a utility class that provides static convenience methods for passing XML data back and forth from the application to Zend_ Db_ Xml_ XmlContent, either for the raw XML data or for the about XML metadata. Though the XML is stored internally as a DOM, Zend_ Db_ Xml_ XmlUtil can allow an application to use strings, file streams, or any other implementation specific object representation of XML data, such as PHP’s SimpleXML. Convenience methods for converting between these different types of representations and DOM are provided. Let us assume the following document is already saved in the persistence layer as shown in below

Sample XML document

To search anywhere for the keyword “Rainbow”, see below

Searching keyword

To be more specific about case and where exactly in the document to search, see below

Detail searching

Get XML iterator

We can also use a simple XPath expression to search as shown in below

Search using XPath expression

This will output Mom, Dad, and The Rainbow house. Parameters are also accepted in XPath searches using an associative array. It is important to match XPath variable names with the keys of the associative array. Otherwise, the XPath search fails. Below shows the XPath search.

Xpath search

This will output “Author: Mary Staple”. An XCS application
In any application environment, there are two types of data used, data for persistent storage and data for message flows. XML is undoubtedly suited for both types of data: XML for messages and XML for persistent storage of data. XML for messages possesses fewer design problems, because each message is self-contained and the application process usually decides what should be included in a message. Contrary to this, while designing the persistent XML data, its static model is very important. The real design challenge is to decide the granularity of data and the size of the XML documents and whether to keep everything in one large document or create a large number of small documents. Irrespective of the size of the XML data, finding information is always a two step process, finding the right document and then finding the desired information within the document. The architecture of XCS makes the XML persistence model easy. Several types of applications benefit from XCS.

Here are few examples:

  • RSS Feed/Blogging Application
  • Users can specify feeds, applications can pull feed data and store it in XCS. Applications can then search and display feeds. Blogs can also be created and stored in XCS. Blogs then can be searched, sorted, and displayed.
  • XML-based Content Management system
  • All types of content can be used to store data in the XCS DATA column. ATTACHMENT can be used to store binary objects such as image data. ABOUT can store the metadata which can drive the application process flow.
  • Web services
  • Web services are the applications that utilize XML messages for interaction between components. Applications can utilize XCS to store, search, and retrieve XML data.

Essentially, any application that requires XML data interchange can benefit from XCS. We have created one application to demonstrate the capability of XCS. Our sample application is a social network application. We named it

This application enables users to:

  • Create and maintain a profile for social and professional networking.
  • Search for people within networks.
  • Make contacts with the people and collaborate with them.

Solution components
This application can be divided into the following functional components:

  • Create and maintain member profile
  • We need a persistent XML storage to store all of our member profiles and relation- ships between them. We also need to build user interfaces for new members to create profiles and log in to the system. We need to track user inputs, build XML with it, and then store it in XCS.

  • Track logged in users
  • We need to track logged in users so that the application knows if a user is viewing the user’s own profile or another user’s profile. This is required to allow users to make contact with other members. We used PHP’s built-in session tracking methods to track the status of logged-in users.

  • Update contacts and relationships
  • We need user interfaces and controller functions to perform the updates on XML data. Luckily, we have XCS implementations of Create, Remove, Update, and Delete (CRUD), so we do not need to worry about underlying database calls. We use XMLContent’s ABOUT property to store members’ relationships.

  • Search
  • We need to implement search, so that users can look for members they want to contact. We utilize XCS’s find functions to implement the search without knowing any XQuery implementation programming.

Solution overview
Below shows the navigation path of the proposed application. In the framework design, the Web page navigation flow should decide how the Controllers and Views should be created.

Navigation diagram for application

Navigation diagram for application

As you can see, we give the user a choice of options. The user can either log in or search for someone who is already using this Web site. A user can search for a member, but the user cannot view a member’s detailed profile until the user logs in. If the user is new, the user is able to create and save the user’s profile in the system. We also give the user the option to find a particular member and make contact with a user-selected relationship. The user also is able to contact others directly via e-mail. The member’s contact information is displayed along with the profile. A summary of the files we use in the myContacts application is shown in below

Files used in myContacts

Files used in myContacts

Let us go ahead and look at the application.

Setting up the database
The database for the myContacts application is fairly simple, because users are able to add new members and relationships using the application itself. We need to store user names and passwords in a DB2 table DB2ADMIN.MEMBER. We also need to create a table required by XCS. You can set up the database for this application by running the SQL on the DB2 Command Line as shown in below

Database setup script

The XML data type is available on any UTF-8 database in the DB2 9 release. With the creation of these database objects, DB2 is now ready for use as an XML Content Store. There are no other DB2 administrative tasks necessary. However, to improve performance when searching, we suggest that you create indexes for the XML data as shown in below

Creating index script

These are very general indexes on all text nodes and attributes on both DATA and ABOUT. The developer might decide to create indexes on elements or attributes for application-specific data, such as a product ID or a last name element where searches might occur often.

Remember that you can run these commands individually or run the script setupdb.sql:

db2 -tvf setupdb.sql

This script is also part of the zip file for the entire application which is downloadable at the redbook Web site.

Getting Started
When a user loads the URL http://localhost/, the user sees the page shown in below Index page Index page

Controllers has the following controllers:

  • IndexController
  • Our IndexController is as clean as it should be. It has a indexAction() method to serve the main Web page (Home page) and a noRouteAction() method to reroute users to the home page in case users become creative and modify the links. below shows the IndexController.php. IndexController.php

When a user tries to log in, a database query is issued and the member’s profile displays. If the member ID is found and the password is validated, the session variable is updated with the user’s ID. The view/member action is invoked and the output looks like this

My Profile page showing logged-in user and his contacts

My Profile page showing logged-in user and his contacts

  • AddController
  • Our AddController contains the following action methods (we discuss these action methods later to explain important concepts):
    – indexAction() to reroute users to the home page
    – memberAction() to add new member data
    – contactAction() to add a relationship between members
    – __call() to handle the calls not defined by any action methods
  • viewController
  • Our viewController contains the following action methods:
    – indexAction() to reroute users to the home page
    – searchAction() to implement existing member searches
    – displayAction() to present the detailed member profile
    – __call() to handle the calls not defined by any action methods such as other database action controls

The application has the following major views:

  • index.php
  • This template presents the home page with two interfaces. The search allows users to find members already in the database. The login window is also provided on this page.
  • member.php
  • This template presents the logged in member’s profile data and also a searched member’s profile data. This also presents the relationship information under the member’s contacts or my contacts.
  • searchResult.php
  • This template displays the search result for a member. The return search result is clickable to get the detailed profile, if the user is logged in.
  • view.php
  • This template provides the interface to the user to create a new profile. The other views, such as thanks.php and error.php, assist users with usefulinformation. There might also exist some views to display the user agreement, privacy policy, customer support information, and other relevant information as shown by the link in the footer.

Note: These might not be necessarily implemented in the code either because they are not important conceptually or beyond the scope of this chapter.

Database class
We created a database class, Database.php, where we implemented the following functions:

  • __construct()
  • This is the database class constructor function to initialize both the dbAdapter connection object and the XMLContentStore connection object.

below it shows __construct().

Database class: constructor method

  • login()
  • This method provides the SQL query to go against the member database to check if the user profile exists. Also, it returns a member’s ID so that the member’s detailed profile can be fetched from XCS. Below shows the login() method.

    Database class: login method

  • getMember()
  • This method implements a database convenience method to retrieve member information from the member table when given the member ID. It uses the simple dbAdapter function to fetch data in a similar way to the login function.

  • search()
  • This method provides some validation and posts an SQL/XML query to get a member’s profile. It provides fuzzy search capability on first and last names. As you can see, we needed to join on the MEMBER table and XMLDATA and use SQL/XML function to get the search result we want. Example 3-28 shows an example of the flexibility of the XCS. If the existing API methods are not sufficient for your needs, you can take control of the database by writing your own SQL queries, SQL/XML queries, or XQueries directly.

    Database class: search method

    This application allows users to create and save their profiles. A user interface is provided as shown in below. Once a user fills in the required text and clicks Join Now, a new member profile is added into the DOC column of the XCS database. This profile is saved as XML. An empty contact data of XML type is also constructed for this profile. When this user updates the user’s contacts, this XML document is updated. With the new profile created, the authentication table is also updated.

    Create a new member profile

    Create a new member profile

  • addMember()
  • This method adds member data into the relational table when a new member profile is created. The member ID is auto-generated for XML detailed profile data, which is, in turn, used for inserting into the member table. Below shows the addMember() function.

    Database class: addMember method

  • saveNew()
  • This method inserts a new XML record into XMLDATA, using XCS’s convenience method insert(). Below shows the saveNew() function.

    Database class: Insert profile

  • getProfile()
  • This method uses XCS’s convenience method findById() that takes docid as input and returns the XML record as an array.Below shows the getProfile() function.

    Database class: Retrieve profile

    The Add Contact/relationship feature allows a member to make contacts with other members and create the chain of professional relationships. The user must log in to view a member’s detailed profile and make the member a contact. The user can select a relationship name from the drop-down box. When the user clicks Make Contact, a XCS update is issued to update XML data in the about column which holds the member contact data. If a duplicate relationship with the same person is found in the database, the application ignores the request and does not make the update. If a user tries to add the user as a contact, an error message is thrown and database update does not occur. Finally, if there is no error, database update succeeds and the user is taken to that user’s own profile page which reflects the currently added contacts. Alternatively, a logged-in user can at any time, click the My Profile menu bar to view that user’s own profile and contact information.Below shows the Web page where a user can define a relationship and make contacts as we discussed.

    Define relationship and make contact

    Define relationship and make contact

  • addContact()
  • This implements a method to add a contact/relationship with an existing myContacts member. From the application point of view, a logged-in member can search for other members by first name and/or last name and then view another member’s detailed profile. The authorized user can add the result member as a contact. It is worth explaining here how XCS makes creation and manipulation of xml data easier. XCS’s Zend_Db_Xml_XmlUtil class provides a convenience method to create a simpleXML representation of the DOM object, which is easy to handle programmatically. Let us discuss the flow here:

    – We get XML data using XCS’s findById() method, passing the $id of authorized user as shown in below

    XCS convenience method findById()

    – xmlContent object now has the XML data. Remember our XML data consists of two XML columns and two non-XML columns. Using the XCS accessor’s method, you can access the data or about contents easily as shown in below, the first parameter is input DOM object and the second parameter is what to retrieve.

    XCS convenience method exportToSimpleXml()

    – Now, since you have a simpleXML representation of your DOM data, you can use any XPath expression to traverse into it and create an array to access the data elements. In this application, we prohibit a user from creating duplicate relationships with the same member and also from creating any relationship with the actual user.Below it shows how to build XML data for contact.

    Building XML data for contact

    – When we are ready to manipulate the XML and put it back into the xmlContent store, we can simply use XCS’s importSimpleXML() method to build the document and the call update() method to store it in XCS, as shown in below

    XCS update

  • processContact()
  • We created the method to get contact/relationship information from XCS and keep in an array variable for easy manipulation and display on the form. It also uses the exportToSimpleXml() convenience method.

Add Controller
Following the framework coding convention, we created controller functions related to update and insert into addController.php. We walk you through the important concepts, while discussing the action methods of addController.php.

In any Web application processing, the user inputs via Web pages and validating them for further processing is not only important but also cumbersome. We do this in the memberAction() method of addController. Zend_Filter_Input is a framework component, which provides simple facilities to promote a structured and rigid approach to input filtering of user data. PHP developers use various types of input filtering techniques, including whitelist filtering, blacklist filtering, regular expressions, conditional statements, and so on, but the good thing about Zend_Filter_Input is that it combines all of these techniques into a single API with consistent behavior and strict naming convention. Zend_Filter_Input is designed primarily with arrays in mind. Many sources of input are already covered by PHP's superglobal arrays ($_GET, $_POST, $_COOKIE, and so on.), and arrays are a common construct used to store input from other sources. If you need to filter a scalar, you can use Zend_Filter component. Zend_Filter_Input supports both a strict and a non-strict approach. In a strict approach, a single array of post variable to be processed is passed into the constructor as shown in below.


Zend_Filter_Input sets the array that is passed ($_POST) to NULL, so direct access is no longer possible. If you need to access it directly and do not want Zend_Filter_Input to set the $_POST array to null, you can use a non-strict approach and pass FALSE as the second parameter.

Zend_Filter_Input non-strict call

Saving Input data into XCS
After we filter and validate the input, we need to save it into persistent store. As shown in Example 3-38, we construct the xml from the $_POST array, create a DOM document, create an XMLContent object, and save it into XCS. Depending on your skill level or the need of the application, you can also construct XML using string concatenation or the PHP’s simpleXML object. You can add these into XMLContent via an XMLContentUtil method call.

Saving data to XCS

Note: The testEmail() function is not available in Zend Framework as of writing this book. You can write your own validation function for e-mail filtering or for our application, we used testAlpha() to validate e-mail. Consider this as an opportunity to get involved with framework community development and contribute to the framework code. Also, for a complete list of available input filtering facilities, refer to the online developers guide at the Zend framework Web site.

Since the php array objects are associative, that is, stored as a $key → $value pair, you can see it is easy to create XML elements and attributes by just looping through the $_POST array.

Modifying data in XCS
If you notice in the previous example, the add/member action adds a member’s profile into data and constructs an empty XML for ABOUT column. An empty element </contacts> is created and stored in XCS. When a logged-in user browses a myContacts member and adds the member as a contact, the add/contact action is invoked. The contactAction invokes the database method addContact, which calls XCS’s update function to update the entire xml document. The db → addContact() method is explained in detail in the previous database section.

Similar to AddController, ViewController must not implement index action. However, this controller should implement a __call() to handle dynamic actions such as the following URL. This makes sure that any URL typing by the user is handled appropriately.


Other Zend Framework components
We have discussed so far only a small portion of the functionalities Zend Framework provides. As mentioned previously, the framework fulfills the promises and provides a rich set of components to build today’s applications quickly. In this section, we briefly go through some of these components. We recommend that you refer to the Zend online manual for the details and examples.

RSS & Atom feeds are hot technologies today and many applications are being built to support them. RSS/Atom is a technology and syndication is a process. Feed is about getting content regularly and sequentially. The core technology is XML on which both are built, and hence, DB2 9 pureXML can be used to store RSS/Atom feeds. XCS makes this job even easier. Zend_Feed provides a natural syntax for accessing elements of feeds, feed attributes, and entry attributes. Zend_Feed also has extensive support for modifying the feed and entry structure with the same natural syntax and turning the result back into XML. In the future, this modification support could provide support for the Atom Publishing Protocol. The Zend online documentation shows an example to demonstrate a simple use case of retrieving an RSS feed and saving relevant portions of the feed data to a simple PHP array, which you could then use for printing the data, storing to a database, and so on.

Zend_Mail provides generalized functionality to compose and send both text and MIME-compliant e-mail messages.You can send mail with Zend_Mail via the php built-in mail() function or via direct SMTP connection. Different options can also be used such as sending HTML e-mail or sending attachments with e-mail. A simple e-mail consists of some recipients, a subject, a body, and a sender. To send mail using the Zend_Mail API, follow below one.

Using Zend_Mail API to send e-mail

The Zend_Pdf module is a PDF (Portable Document Format) manipulation engine written entirely in PHP 5. It can load existing documents, create new documents, modify documents, and save modified documents. Thus, it can help any PHP-driven application dynamically prepare documents in a PDF by modifying an existing template or generating a document from scratch. The Zend_Pdf module supports the following features:

  • Create new document or load existing one
  • Retrieve specified revision of the document
  • Manipulate pages within document
  • Change page order, add new pages, and remove pages from a document
  • Use different drawing primitives (lines, rectangles, polygons, circles, ellipses, and sectors)
  • Allow text drawing using any of the 14 standard (built-in) fonts or your own custom TrueType fonts
  • Handle rotations
  • Perform image drawing
  • Do incremental PDF file update

Creating Web services with Zend Framework
Web services are Web-based enterprise applications that use open, XML-based standards and transport protocols to exchange data with calling clients. Many vendors including Amazon, Yahoo, and eBay offer numerous Web services that you can use for free. This section describes the Web services components of Zend Framework. You can create a simple Web service using Zend_Service_Flickr to search a Flickr (a Yahoo company) image.

Zend Framework preview release 0.1.4 comes with these Web services components, which you can use to build a Web services application. We anticipate that more Web service APIs will be added as the Framework matures toward a 1.0 release.

Zend_Service_Amazon is a simple API for using Amazon Web services. Zend_ Service_ Amazon has two APIs: A more traditional one that follows Amazon's own API, and a simpler “Query API” for constructing even complex search queries easily. Zend_Service_Amazon enables developers to retrieve information appearing throughout Web sites directly through the Amazon Web Services API. Some of the examples are:

  • Store item information, such as images, descriptions, pricing, and more
  • Customer and editorial reviews
  • Similar products and accessories
  • offers
  • ListMania lists

Zend_Service_Yahoo is a simple API for using many of the Yahoo REST APIs. Zend_ Service_ Yahoo allows you to search Yahoo! Web search, Yahoo! News, Yahoo! Local, Yahoo! Images, and more.

Zend_Service_Yahoo enables you to search the Web with Yahoo! using the webSearch() method, which accepts a string query parameter and an optional second parameter as an array of search options. For full details and an option list.

You can search for Images with Yahoo using Zend_Service_Yahoo's imageSearch() method. This method accepts a string query parameter and an optional array of search options. similar to the webSearch() method. For fulldetails and an option list. In order to use the Yahoo Web services API, you must acquire a Web services application ID.

Flickr is a Yahoo company that offers free services for managing and sharing pictures. Flickr also provides Web services APIs for developers to build Web applications using these APIs.

Zend_Service_Flickr is a simple API for using the Flickr REST Web Service. In order to use the Flickr Web services, you must have an API key. In order to show you the simplicity of the Web service API, we chose to create a Web service application that searches for images for a user given keyword at Flickr Web site and brings the links to the images. The user can click on the links and display the images. In the Zend Framework MVC architecture, you ideally create a separate controller and templates to build this Web service code, but for simplicity, we created a photoAction() method in the existing IndexController.php. The code for photoAction() is shown in below

photoAction() method

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

IBM DB2 Topics