Views - AR Classes Update
Available from Prado versions 3.3 onwards.
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);
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();
$this->tryToUpdateAR($student);
$student->save();
Info:
Note that the identifiers of your controls should be exactly the same of the attributes of your
AR Classes... otherwise nothing will happen.