| 1 |
lars |
1 |
<com:TContent ID="body">
|
|
|
2 |
|
|
|
3 |
<h1>Playtest second!</h1>
|
|
|
4 |
<p>Now that we have a passing test, we want to display some results as web pages.
|
|
|
5 |
The following examples utilize the Prado framework to display and manipulate
|
|
|
6 |
the database through SQLMap. Since SQLMap framework and Prado framework solve
|
|
|
7 |
different problems, they are both fairly independent, they can be used
|
|
|
8 |
together or separately.</p>
|
|
|
9 |
|
|
|
10 |
<h2>SQLMap and Prado</h2>
|
|
|
11 |
<p>To setup Prado, we need to create the follow files and directory structure
|
|
|
12 |
under our <tt>example/WebView</tt> directory.</p>
|
|
|
13 |
<com:TTextHighlighter Language="code" CssClass="source">
|
|
|
14 |
assets/ % application public assets
|
|
|
15 |
|
|
|
16 |
protected/pages/Home.page % default page
|
|
|
17 |
protected/pages/Home.php % default page class
|
|
|
18 |
protected/runtime/ % run time data
|
|
|
19 |
|
|
|
20 |
protected/application.xml % application configuration
|
|
|
21 |
|
|
|
22 |
index.php % application entry point
|
|
|
23 |
</com:TTextHighlighter>
|
|
|
24 |
|
|
|
25 |
<p>The <tt>application.xml</tt> and <tt>assets</tt> directory are not necessary but we
|
|
|
26 |
will make use of them later. The <tt>application.xml</tt> is used to define some
|
|
|
27 |
directory aliases and override the data source definitions in the
|
|
|
28 |
<tt>sqlmap.config</tt>. This is because SQLite database files are defined
|
|
|
29 |
relatively, otherwise we don't need to override the data source definitions.
|
|
|
30 |
The example <tt>application.xml</tt> is shown below, defining path aliases and override SQLite database
|
|
|
31 |
location.</p>
|
|
|
32 |
|
|
|
33 |
<com:TTextHighlighter Language="xml" CssClass="source">
|
|
|
34 |
<?xml version="1.0" encoding="utf-8"?>
|
|
|
35 |
<application id="SQLMap Example" Mode="Debug">
|
|
|
36 |
<paths>
|
|
|
37 |
<alias id="Example" path="../../" />
|
|
|
38 |
<using namespace="System.DataAccess.*" />
|
|
|
39 |
</paths>
|
|
|
40 |
<modules>
|
|
|
41 |
<module id="SQLMap" class="TSQLMap"
|
|
|
42 |
configFile="Example.sqlmap">
|
|
|
43 |
<!-- override sqlmap.config's database provider -->
|
|
|
44 |
<provider class="TAdodbProvider">
|
|
|
45 |
<datasource driver="sqlite" host="../Data/test.db" />
|
|
|
46 |
</provider>
|
|
|
47 |
</module>
|
|
|
48 |
</modules>
|
|
|
49 |
</application>
|
|
|
50 |
</com:TTextHighlighter>
|
|
|
51 |
|
|
|
52 |
<p>The entry point to a Prado application in this example is <tt>index.php</tt>
|
|
|
53 |
and generally contains the following code.</p>
|
|
|
54 |
|
|
|
55 |
<com:TTextHighlighter Language="php" CssClass="source">
|
|
|
56 |
<?php
|
|
|
57 |
error_reporting(E_ALL);
|
|
|
58 |
require_once('/path/to/prado/framework/prado.php');
|
|
|
59 |
$application=new TApplication;
|
|
|
60 |
$application->run();
|
|
|
61 |
?>
|
|
|
62 |
</com:TTextHighlighter>
|
|
|
63 |
|
|
|
64 |
<p>Now we are ready to setup a page to display our list of people.
|
|
|
65 |
The following sample shows the Prado code for our display page. The key
|
|
|
66 |
piece is the <tt>TDataGrid</tt>. We save the file as <tt>Home.page</tt>.</p>
|
|
|
67 |
|
|
|
68 |
<com:TTextHighlighter Language="prado" CssClass="source">
|
|
|
69 |
<!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
|
70 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
|
71 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
|
|
72 |
<head>
|
|
|
73 |
<title>Person</title>
|
|
|
74 |
</head>
|
|
|
75 |
<body>
|
|
|
76 |
<com:TForm>
|
|
|
77 |
<h1>Person List</h1>
|
|
|
78 |
<com:TDataGrid id="personList">
|
|
|
79 |
<com:TBoundColumn DataField="BirthDate"
|
|
|
80 |
HeaderText="Birth Date"/>
|
|
|
81 |
</com:TDataGrid>
|
|
|
82 |
</com:TForm>
|
|
|
83 |
</body>
|
|
|
84 |
</html>
|
|
|
85 |
</com:TTextHighlighter>
|
|
|
86 |
|
|
|
87 |
<p>Of course, we still need to populate that TDataGrid. The following code
|
|
|
88 |
shows the PHP for <tt>Home.php</tt>. The operative method is <tt>loadData()</tt>.
|
|
|
89 |
The rest is supporting code.</p>
|
|
|
90 |
|
|
|
91 |
<com:TTextHighlighter Language="php" CssClass="source">
|
|
|
92 |
<?php
|
|
|
93 |
Prado::using('Example.Models.Person');
|
|
|
94 |
class Home extends TPage
|
|
|
95 |
{
|
|
|
96 |
private function loadData()
|
|
|
97 |
{
|
|
|
98 |
$sqlmap = $this->Application->getModule('SQLMap')->getClient();
|
|
|
99 |
$this->personList->DataSource = $sqlmap->queryForList('SelectAll');
|
|
|
100 |
$this->personList->dataBind();
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
public function onLoad($param)
|
|
|
104 |
{
|
|
|
105 |
if(!$this->IsPostBack)
|
|
|
106 |
$this->loadData();
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
?>
|
|
|
110 |
</com:TTextHighlighter>
|
|
|
111 |
|
|
|
112 |
<p>If we run this now, we'll get a list like the one shown the figure below.</p>
|
|
|
113 |
<img src=<%~ grid1.png %> class="figure" />
|
|
|
114 |
<div class="caption"><b>Figure 3:</b> A quick-and-dirty Person List</div>
|
|
|
115 |
|
|
|
116 |
</com:TContent>
|