Exemplo n.º 1
0
 /**
  * Updates an existing Post model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $categoryModel = new CategoryPost();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'treeParents' => $treeParents]);
     }
 }
Exemplo n.º 2
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $categoryModel = new ProductCategory();
     $companyModel = new ProductCompany();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     $treeCompany = ArrayHelper::map($companyModel->findAll(['status' => 10]), 'id', 'title');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'treeParents' => $treeParents, 'treeCompany' => $treeCompany]);
     }
 }
 /**
  * Updates an existing ProductCategory model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $treeParents = TreeHelper::build($model->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     if ($model->load(Yii::$app->request->post())) {
         if (empty($model->parent_id)) {
             $model->save();
         } else {
             $root = $model->findOne(['id' => $model->parent_id]);
             $model->appendTo($root);
         }
         return $this->redirect(['index']);
     } else {
         return $this->render('update', ['model' => $model, 'treeParents' => $treeParents]);
     }
 }