From fa0164d84c82932d1dd4268386bbb28abbe68557 Mon Sep 17 00:00:00 2001 From: "Daniel Sampedro B." Date: Thu, 29 Jan 2015 17:35:59 -0500 Subject: Views - AR Classes Update Documentation 100% --- .../protected/pages/Database/ViewsArUpdate.page | 40 ++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'demos/quickstart/protected') diff --git a/demos/quickstart/protected/pages/Database/ViewsArUpdate.page b/demos/quickstart/protected/pages/Database/ViewsArUpdate.page index a2f7ff68..5dd084c4 100644 --- a/demos/quickstart/protected/pages/Database/ViewsArUpdate.page +++ b/demos/quickstart/protected/pages/Database/ViewsArUpdate.page @@ -2,18 +2,44 @@

Views - AR Classes Update

- Usually when have Active Records Classes - there are correspondingly the proper views to handle them. + Usually when you use Active Records Classes 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.

+

Updating views from AR Classes

+ +

Instead of assign each attribute in your AR Class to your view controls like this:

+ +$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; + + +

You can do the same as follows:

+ $student = AR_Student::finder()->findByPk(1); $this->tryToUpdateView($student); -

- Also you can do the reverse operation. -

+ +

Updating AR Classes from views

+

Instead of assign each attribute in your views to your AR Classes like this:

+ +$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(); + + +

You can do the same as follows:

$student = new AR_Student(); @@ -21,8 +47,10 @@ $this->tryToUpdateAR($student); $student->save(); +
Info: - When an AR class attribute does not match any of the controls IDs on the view, nothing will happen + Note that the identifiers of your controls should be exactly the same of the attributes of your + AR Classes... otherwise nothing will happen.
\ No newline at end of file -- cgit v1.2.3