summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/Database/ViewsArUpdate.page
blob: 2df1d3d7b79369df2883cc267d46ae721dc1ce92 (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
<com:TContent ID="body" >
<h1 id="138046">Views - AR Classes Update</h1>
<com:SinceVersion Version="3.3" />
<p class="block-content">
    Usually when you use <tt>Active Records Classes</tt> to interact with your Data Base
    you also build some proper views to handle them. To save every element of your views in your Data Base
    you need first to assign everyone of them to their corresponding attribute in one of your AR Classes.
    This task is really tedious and usually takes a significant amount of your time.
    Thats why Prado offers an automatic mechanism to update your views from your AR Classes and vice versa. 
</p>

<h2 id="244034">Updating views from AR Classes</h2>

<p id="1220005" class="block-content">Instead of assign each attribute in your AR Class to your view controls like this:</p>
<com:TTextHighlighter CssClass="source block-content">
$student = AR_Student::finder()->findByPk(1);
$this->name->Text = $student->name;
$this->age->Text = $student->age;
$this->gender->Text = $student->gender;
$this->average->Text = $student->average;
</com:TTextHighlighter>

<p id="1220006" class="block-content">You can do the same as follows:</p>

<com:TTextHighlighter CssClass="source block-content">
$student = AR_Student::finder()->findByPk(1);
$this->tryToUpdateView($student);
</com:TTextHighlighter>


<h2 id="244035">Updating AR Classes from views</h2>
<p id="1220007" class="block-content">Instead of assign each attribute in your views to your AR Classes like this:</p>
<com:TTextHighlighter CssClass="source block-content">
$student = new AR_Student();
$student->name = $this->name->Text;
$student->age = $this->age->Text;
$student->gender = $this->gender->Text;
$student->average = $this->average->Text;
$student->save();
</com:TTextHighlighter>

<p id="1220008" class="block-content">You can do the same as follows:</p>

<com:TTextHighlighter CssClass="source block-content">
$student = new AR_Student();
$this->tryToUpdateAR($student);
$student->save();
</com:TTextHighlighter>


<div class="info"><b class="note">Info:</b>
    Note that the identifiers of your controls should be exactly the same of the attributes of your 
    AR Classes... otherwise nothing will happen.
</div>

</com:TContent>