PHP DevCenter

oreilly.comSafari Books Online.Conferences.

We've expanded our LAMP news coverage and improved our search! Search for all things LAMP across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to PHP Subscribe to Newsletters

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:

CREATE DATABASE todo;
      
CREATE TABLE `Task` (
      `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:

|_Todo/
   |_templates/
   |_templates_c/

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:

|_Todo/
   |_db/
   |_templates/
   |_templates_c/

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:

|_Todo/
   |_db/
   |_templates/
   |_templates_c/
|_Entry/
   |_templates/

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

Pages: 1, 2, 3, 4, 5

Next Pagearrow




Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com