PHP DevCenter
oreilly.comSafari Books Online.Conferences.


Simplify PHP Development with WASP
Pages: 1, 2, 3, 4, 5

The Database

The next thing to configure is the database model. Because this is an introductory tutorial, I wanted to keep it simple. Here is the SQL needed to create the table for the task list application:

      `TaskId` bigint(20) NOT NULL auto_increment,
      `Due` date NOT NULL,
      `Name` text NOT NULL,
      PRIMARY KEY  (`TaskId`)

The Task table has three columns. For WASP applications, I strongly recommend that all tables have some kind of id column as a primary key. TaskId is the primary key column. Due is the due date of task, and Name is a column for the name or title of the task.

Writing the Application

Now that you have successfully installed WASP and created the database, it's time to write the code for the task list program.

Model, Views, and Controllers

The next step is to create the model, controllers, and views for the application. To do this, there are build targets in the build.xml that you can use by calling them through Phing.

Don't be scared of the terms used here. "Model" is just a fancy name for the database objects. The "view" is be the HTML code for the pages, and the "controller" is just PHP code that decides what pages to draw and how to handle data from the model.

Create the application and generate the main controller and view objects:

$ phing app

Choose the name Todo when prompted.

This creates the main application directory where your code will reside and execute, as well as the initial model and controller classes for the application.

From within the directory you specified as app.dir (or the current directory, if unspecified) you should now have the following subdirectories:


In the Todo/ directory you have the controller classes TodoMainModule.php and TodoMainIndexPage.php, and the controller index.php file.

The templates/ directory is where the view resides. It holds all of the "chunk" or template files. These are where you will write all of the HTML and Flexy code for your application. There is a one to one relationship between Chunk classes and .chunk files. In this case, TodoMainIndexPage extends wasp.gui.Chunk, and refers to the index.chunk template. Don't worry if this doesn't make much sense now; it'll all fall into place in the coming sections.

The templates_c/ directory is where compiled Flexy templates reside. Make sure you grant your web server permission to write to this directory.

Next, create the data model objects.

$ phing db

The directory structure should now look like this:


The db/ directory holds all of the model classes. In this case, you simply have TaskWrapper.php. There will be one model class for each table in the database.

You will need a module in the application for creating todo entries, so create the new todo "Entry" module.

$ phing module

Choose the name "Entry" when prompted. The directory tree will now look like:


There are more controller classes and view chunks in the Entry directories.

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: