Esempio n. 1
0
 /**
  * Deletes an existing Category model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param string $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->setMenus(30, "删除分类");
     $model = $this->findModel($id);
     //判断是否有子项
     if (Category::findAll(['pid' => $id])) {
         return $this->redirect(['index', 'message' => LsYii::gT('该分类还有子项,不能被删除'), 'type' => 2]);
     }
     if ($model->if_delete == \source\libs\Constants::If_Delete_Prohibit) {
         return $this->redirect(['index', 'message' => LsYii::gT('该分类不允许被删除'), 'type' => 2]);
     }
     $rgt = $model->rgt;
     if ($model->delete()) {
         Category::updateAllCounters(['rgt' => -2], "`lft`<{$rgt} AND `rgt`>={$rgt}");
         Category::updateAllCounters(['rgt' => -2, 'lft' => -2], "`lft`>{$rgt}");
         $message = LsYii::gT('删除成功');
         $type = 1;
     } else {
         $message = LsYii::gT('删除失败');
         $type = 2;
     }
     return $this->redirect(['index', 'message' => $message, 'type' => $type]);
 }