blob: 9afe4a3f05a6b77f9d7d43820da2013d9375e329 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
<com:TContent ID="body" >
<!-- $Id$ -->
<h1>Active Record Scaffold Views</h1>
<com:SinceVersion Version="3.1b" />
<p><a href="?page=Database.ActiveRecord">Active Record</a> classes can be used together with
<com:DocLink ClassPath="System.Data.ActiveRecord.Scaffold.TScaffoldListView" Text="TScaffoldListView"/>
and
<com:DocLink ClassPath="System.Data.ActiveRecord.Scaffold.TScaffoldEditView" Text="TScaffoldEditView"/>
( <com:DocLink ClassPath="System.Data.ActiveRecord.Scaffold.TScaffoldView" Text="TScaffoldView"/>
links both <tt>TScaffoldListView</tt> and <tt>TScaffoldEditView</tt>) to create
<i>simple</i> Create/Read/Update/Delete (CRUD) web applications.</p>
<p>The scaffold views are intended to assist in prototyping web application,
they are not designed to be as customiziable as more complex components such as
<a href="?page=Controls.DataGrid">TDataGrid</a>. The scaffold views provide
the following builtin functionality:
</p>
<ul>
<li>Listing of all active record items.</li>
<li>Searching records.</li>
<li>Paging and sorting.</li>
<li>Deleting an item.</li>
<li>Inserting a new item.</li>
<li>Updating an existing item.</li>
<li>Validates required fields and basic data types.</li>
<li>Presents specialized controls such as date pickers.</li>
</ul>
<p>Scaffold views are dependent on Active Records and currently supports
the following databases: Mysql, Sqlite and Postgres SQL. Support for other databases
can be considered when there are sufficient demand.</p>
<h2>Setting up a Scaffold View</h2>
<p>To use the scaffold view, we first define an <a href="?page=Database.ActiveRecord">Active Record</a>
class that represents a table or view in the database. Consider the following
Active Record class that corresponds to the <tt>users</tt>
table as defined in the <a href="?page=Database.ActiveRecord">Active Record</a> quickstart page.
</p>
<com:TTextHighlighter Language="php" CssClass="source">
class UserRecord extends TActiveRecord
{
const TABLE='users';
public $username;
public $email;
}
</com:TTextHighlighter>
<p>The scaffold view classes are in the <tt>System.Data.ActiveRecord.Scaffold.*</tt>
<a href="?page=Fundamentals.Components#704">namespace</a>.
This <a href="?page=Fundamentals.Components#704">namespace</a> can be "imported" in the
<a href="?page=Configurations.AppConfig">Application Configuration</a>
using the <tt>application.xml</tt> file or through the php code using the <tt>Prado::using()</tt>
method. To start using the
<com:DocLink ClassPath="System.Data.ActiveRecord.Scaffold.TScaffoldView" Text="TScaffoldView"/>
simply set the <tt>RecordClass</tt> property value equal to an Active Record
class name.
</p>
<com:TTextHighlighter Language="prado" CssClass="source">
<com:TScaffoldView RecordClass="UserRecord" />
</com:TTextHighlighter>
<p>The above code will list the current records in the <tt>users</tt> table.
Each record can be edited by clicking on the "edit" button and deleted by
clicking on the "delete" button. A new record can be added by clicking on the
"Add new record" button, enter some data (notice the automatic validation of required fields and data types), and click the "save" button.
Specifying search terms in the search textbox to find particular records. Finally, the
record list can be sorted for each column by changing the sorting column and order.
</p>
<p>The <tt>TScaffoldView</tt> is a template control composed of other scaffold controls.
The following properties gives access to these composite controls.</p>
<ul>
<li><b><tt>ListView</tt></b> -- the <tt>TScaffoldListView</tt> displaying the record list. </li>
<li><b><tt>EditView</tt></b> -- the <tt>TScaffoldEditView</tt> that renders the inputs for editing and adding records.</li>
<li><b><tt>SearchControl</tt></b> -- the <tt>TScaffoldSearch</tt> responsible to the search user interface.</li>
</ul>
<p>
All these composite controls can be customized as we shall see below.
</p>
<h2>TScaffoldListView</h2>
<p>A list of Active Records can be displayed using the <tt>TScaffoldListView</tt>
with the following useful properties.</p>
<ul>
<li><b><tt>Header</tt></b> -- a <a href="?page=Controls.Repeater">TRepeater</a>
displaying the Active Record property/field names. </li>
<li><b><tt>Sort</tt></b> -- a <a href="?page=Controls.List">TDropDownList</a> displaying the combination
of properties and its possible ordering. </li>
<li><b><tt>Pager</tt></b> -- a <a href="?page=Controls.Pager">TPager</a> control displaying
the links and/or buttons that navigate to different pages in the Active Record data.</li>
<li><b><tt>List</tt></b> -- a <a href="?page=Controls.Repeater">TRepeater</a> that renders a row of Active Record data.</li>
</ul>
<p>Custom rendering of the each Active Record can be achieved by specifying
the <tt>ItemTemplate</tt> and/or <tt>AlternatingItemTemplate</tt> property of the <tt>List</tt>
repeater.
The <tt>TScaffoldListView</tt> will listen for two command events named "delete" and
"edit". A "delete" command will delete a the record for the row where the "delete" command originates.
An "edit" command will push the record data to be edited by a
<tt>TScaffoldEditView</tt> with ID specified by the <tt>EditViewID</tt> property.
The following example lists the usernames only with bold formatting.
</p>
<com:TTextHighlighter Language="prado" CssClass="source">
<com:TScaffoldListView RecordClass="UserRecord" >
<prop:List.ItemTemplate>
<strong><%# $this->Data->username %></strong>
</prop:List.ItemTemplate>
</com:TScaffoldListView>
</com:TTextHighlighter>
<div class="info"><b class="note">Info:</b>
For the <tt>TScaffoldView</tt> the list view can be accessed throught the <tt>ListView</tt> property of a <tt>TScaffoldView</tt>.
Thus, the subproperty <tt>ListView.List.ItemTemplate</tt> on <tt>TScaffoldView</tt>
is equivalent to the <tt>List.ItemTemplate</tt> subproperty of <tt>TScaffoldListView</tt> in the above example.
</div>
<p>The <tt>SearchCondition</tt> property and
<tt>SearchParameters</tt> property (takes array values) can be
specified to customize the records to be shown. The <tt>SearchCondition</tt>
will be used as the <tt>Condition</tt> property of <tt>TActiveRecordCriteria</tt>
and the <tt>SearchParameters</tt> property corresponds to
<tt>Parameters</tt> property of <tt>TActiveRecordCriteria</tt>.</p>
<h2>TScaffoldEditView</h2>
<com:TTextHighlighter Language="prado" CssClass="source">
<com:TScaffoldEditView RecordPk="user1" RecordClass="UserRecord" />
</com:TTextHighlighter>
<h2>Combining list + edit views</h2>
<com:TTextHighlighter Language="prado" CssClass="source">
<com:TScaffoldEditView ID="edit_view" RecordClass="UserRecord" />
<com:TScaffoldListView EditViewID="edit_view" RecordClass="UserRecord" />
</com:TTextHighlighter>
<h2>Customizing the TScaffoldView</h2>
<com:TTextHighlighter Language="prado" CssClass="source">
<com:TScaffoldView RecordClass="UserRecord" >
<prop:ListView.List.ItemTemplate>
<%# $this->DataItem->username %>
<com:TLinkButton Text="Edit" CommandName="edit" />
</prop:ListView.List.ItemTemplate>
</com:TScaffoldView/>
</com:TTextHighlighter>
<div class="last-modified">$Id$</div></com:TContent>
|