PHP DevCenter
oreilly.comSafari Books Online.Conferences.


Simplify PHP Development with WASP

Add Tag Clouds to Your Site

WASP (Web Application Structure for PHP) is a three-tier framework built on PHP 5. Lately, more software engineers are moving from cumbersome "enterprise" languages such as Java and C# to languages such as Python and Ruby and PHP. With version 5, PHP has finally reached the point where these developers can feel at home in what used to be considered a hacker's language. By demonstrating that it is possible to create and use complicated, "enterprise-class" frameworks effectively in PHP 5, WASP will help more developers make the switch.

WASP's initial basis is in the ideas mentioned in the article "Three-Tier Development with PHP 5." Since then, it has come a long way toward bridging the gap between PHP frameworks and other, traditionally more accepted three-tier tools. PangoMedia has put it to large-scale use in several production applications.

This article demonstrates how to build a small database-driven application: a simple task-list web application. This example is short; however, it demonstrates most of the powerful features that WASP has to offer.

The code in this article uses WASP 1.1. Some familiarity with PHP 5 syntax is helpful, but not necessary. For more information on the methods and classes used in this tutorial, see the WASP API documentation. For additional reference, the following resources may be helpful:

Installation and Configuration

Download and install the latest version of WASP via the PEAR package manager. For detailed instructions, see the WASP Installation and Configuration guide.

Create a WASP project by running the command:

phing -buildfile PEAR_DIR/lib/php/data/WASP/build.xml wasp-project

where PEAR_DIR is the installed location of your PEAR classes. You can find out where this directory is by running:

$ pear config-get php_dir

If all is well, you will see:

Buildfile: /usr/local/php5/lib/php/data/WASP/build.xml
WASP > wasp-project:
Directory to create project in  >

Enter the fully qualified path where your new WASP project will be created. This will create the directory and copy over the build.xml and files.

For the purposes of this example, I've used /Users/brianfioca/Development/projects/Todo.

Make sure the directory you choose is accessible from within your web server's root.

You should now have a directory called Todo that looks like this:


WASP uses Phing and the file to manage its configuration. When you create your application, the Phing tool reads your and builds the correct configuration files for your project.

Here is a file that has default values for this tutorial.
# DESC: wasp project configuration properties file
# The properties below are used to configure your wasp application.
# Set these properties to customize your wasp install.
# run phing config to regenerate the configuration when these are changed.
# The name of the application       Todo
# Toggle Debug output 
debug.flag=     True
# Toggle for email of error messages
email.flag=     False 
session.flag=  True
# URL of the database for this application
database.url=   mysql://user:pass@localhost/todo
# Directory where pear packages are installed
pear.dir=       /usr/local/php5/lib/php

In the configuration, the property is Todo, which will be the name of the application as well as the name of the root directory (located off of the app.dir directory or the wasp directory, if not specified) of all modules, chunks, and templates that the build tool will create.

The app.dir property is the directory where the application will reside within your web root. For this example, I've set the app.dir to /var/www. This is the directory that the Apache HTTP server considers its root directory. Change this directory to match your particular web server configuration. When the application is installed, it'll reside in /var/www/Todo.

Set the pear.dir property to the location of your PEAR classes: the directory that contains DB/DataObject and HTML/Template/Flexy. As I mentioned before, you can also find the location of this directory by running:

$ pear config-get php_dir

Set the database.url property to the URL of the database that your project will use. This example assumes you will be creating a database called todo on the MySQL instance on the local host.

If at any point you wish to regenerate the configuration, run the command:

$ phing config
Building Tag Clouds in Perl and PHP

Essential Reading

Building Tag Clouds in Perl and PHP
By Jim Bumgardner

Tag clouds are everywhere on the web these days. First popularized by the web sites Flickr, Technorati, and, these amorphous clumps of words now appear on a slew of web sites as visual evidence of their membership in the elite corps of "Web 2.0." This PDF analyzes what is and isn't a tag cloud, offers design tips for using them effectively, and then goes on to show how to collect tags and display them in the tag cloud format. Scripts are provided in Perl and PHP.

Yes, some have said tag clouds are a fad. But as you will see, tag clouds, when used properly, have real merits. More importantly, the skills you learn in making your own tag clouds enable you to make other interesting kinds of interfaces that will outlast the mercurial fads of this year or the next.

Read Online--Safari
Search this book on Safari:

Code Fragments only

Pages: 1, 2, 3, 4, 5

Next Pagearrow

Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!

Sponsored by: