Playtest second!

Now that we have a passing test, we want to display some results as web pages. The following examples utilize the Prado framework to display and manipulate the database through SQLMap. Since SQLMap framework and Prado framework solve different problems, they are both fairly independent, they can be used together or separately.

SQLMap and Prado

To setup Prado, we need to create the follow files and directory structure under our example/WebView directory.

assets/                         % application public assets

protected/pages/       % default page
protected/pages/Home.php        % default page class
protected/runtime/              % run time data

protected/application.xml       % application configuration

index.php                       % application entry point

The application.xml and assets directory are not necessary but we will make use of them later. The application.xml is used to define some directory aliases and override the data source definitions in the sqlmap.config. This is because SQLite database files are defined relatively, otherwise we don't need to override the data source definitions. The example application.xml is shown below, defining path aliases and override SQLite database location.

<?xml version="1.0" encoding="utf-8"?>
<application id="SQLMap Example" Mode="Debug">
    <alias id="Example" path="../../" />
    <using namespace="System.DataAccess.*" />
    <module id="SQLMap" class="TSQLMap"
        <!-- override sqlmap.config's database provider -->
        <provider class="TAdodbProvider">
            <datasource driver="sqlite" host="../Data/test.db" />

The entry point to a Prado application in this example is index.php and generally contains the following code.

$application=new TApplication;

Now we are ready to setup a page to display our list of people. The following sample shows the Prado code for our display page. The key piece is the TDataGrid. We save the file as

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8" />
    <h1>Person List</h1>
    <com:TDataGrid id="personList">
        <com:TBoundColumn DataField="BirthDate"
                HeaderText="Birth Date"/>

Of course, we still need to populate that TDataGrid. The following code shows the PHP for Home.php. The operative method is loadData(). The rest is supporting code.

class Home extends TPage
    private function loadData()
        $sqlmap = $this->Application->getModule('SQLMap')->getClient();
        $this->personList->DataSource = $sqlmap->queryForList('SelectAll');

    public function onLoad($param)

If we run this now, we'll get a list like the one shown the figure below.

Figure 3: A quick-and-dirty Person List