AttributeForm::loadDataFromAttribute PHP Method

loadDataFromAttribute() public method

public loadDataFromAttribute ( $id )
    public function loadDataFromAttribute($id)
    {
        $attribute = Attribute::model()->findByPk($id);
        if (!is_null($attribute)) {
            $this->id = $attribute->attribute_id;
            $this->name = $attribute->description->name;
            $this->group = $attribute->attribute_group_id;
            $this->sortOrder = $attribute->sort_order;
        }
    }

Usage Example

 public function actionUpdate($id)
 {
     $model = new AttributeForm();
     if (isset($_POST['AttributeForm'])) {
         $model->attributes = $_POST['AttributeForm'];
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     } else {
         $model->loadDataFromAttribute($id);
     }
     $groups = CHtml::listData(AttributeGroupDescription::model()->findAll(), 'attribute_group_id', 'name');
     $this->render('create', array('model' => $model, 'groups' => $groups));
 }