Prado\Web\UI\TTemplateControl::tryToUpdateView PHP Method

tryToUpdateView() public method

View controls and AR object need to have the same name in IDs and Attrs respectively.
Author: Daniel Sampedro ([email protected])
public tryToUpdateView ( TActiveRecord $arObj, boolean $throwExceptions = false )
$arObj TActiveRecord
$throwExceptions boolean Wheter or not to throw exceptions
    public function tryToUpdateView($arObj, $throwExceptions = false)
    {
        $objAttrs = get_class_vars(get_class($arObj));
        foreach (array_keys($objAttrs) as $key) {
            try {
                if ($key != "RELATIONS") {
                    $control = $this->{$key};
                    if ($control instanceof TTextBox) {
                        $control->Text = $arObj->{$key};
                    } elseif ($control instanceof TCheckBox) {
                        $control->Checked = (bool) $arObj->{$key};
                    } elseif ($control instanceof TDatePicker) {
                        $control->Date = $arObj->{$key};
                    }
                } else {
                    foreach ($objAttrs["RELATIONS"] as $relKey => $relValues) {
                        $relControl = $this->{$relKey};
                        switch ($relValues[0]) {
                            case TActiveRecord::BELONGS_TO:
                            case TActiveRecord::HAS_ONE:
                                $relControl->Text = $arObj->{$relKey};
                                break;
                            case TActiveRecord::HAS_MANY:
                                if ($relControl instanceof TListControl) {
                                    $relControl->DataSource = $arObj->{$relKey};
                                    $relControl->dataBind();
                                }
                                break;
                        }
                    }
                    break;
                }
            } catch (Exception $ex) {
                if ($throwExceptions) {
                    throw $ex;
                }
            }
        }
    }