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`) );
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,
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.