CategoryForm::loadDataFromCategory PHP Method

loadDataFromCategory() public method

public loadDataFromCategory ( $id )
    public function loadDataFromCategory($id)
    {
        $category = Category::model()->findByPk($id);
        if (!is_null($category)) {
            $this->id = $category->category_id;
            $this->name = $category->description->name;
            $this->metaTagDescription = $category->description->meta_description;
            $this->metaTagKeywords = $category->description->meta_keyword;
            $this->description = $category->description->getDescription();
            $this->image = $category->image;
            $this->top = $category->top;
            $this->columns = $category->column;
            $this->sortOrder = $category->sort_order;
            $this->status = $category->status;
            $this->parent = $category->parent_id;
            $this->seoKeyword = $category->getSEOKeyword();
            // Stores
            if (isset($category->stores) && count($category->stores)) {
                foreach ($category->stores as $store) {
                    $this->stores[$store->store_id] = $store->name;
                }
            }
            // Filters
            if (isset($category->filters) && count($category->filters)) {
                foreach ($category->filters as $filter) {
                    $this->filters[$filter->filter_id] = $filter->description->name;
                }
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function actionUpdate($id)
 {
     $model = new CategoryForm();
     if (isset($_POST['CategoryForm'])) {
         $model->attributes = $_POST['CategoryForm'];
         if ($model->validate()) {
             $model->save();
             $this->redirect(array('index'));
         }
     } else {
         $model->loadDataFromCategory($id);
     }
     $statuses = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled'));
     $stores = CHtml::listData(Store::model()->findAll(), 'store_id', 'name');
     $stores[0] = Yii::t('store', 'Default');
     $this->render('update', array('model' => $model, 'stores' => $stores, 'statuses' => $statuses));
 }