Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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