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/Home.page % 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.

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

<?php error_reporting(E_ALL); require_once('/path/to/prado/framework/prado.php'); $application=new TApplication; $application->run(); ?>

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 Home.page.

Person <com:TForm>

Person List

<com:TDataGrid id="personList"> <com:TBoundColumn DataField="BirthDate" HeaderText="Birth Date"/> </com:TDataGrid> </com:TForm>

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.

<?php Prado::using('Example.Models.Person'); class Home extends TPage { private function loadData() { $sqlmap = $this->Application->getModule('SQLMap')->getClient(); $this->personList->DataSource = $sqlmap->queryForList('SelectAll'); $this->personList->dataBind(); } public function onLoad($param) { if(!$this->IsPostBack) $this->loadData(); } } ?>

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

class="figure" />
Figure 3: A quick-and-dirty Person List