示例#1
0
 public function actionView($sid)
 {
     $model = Page::find()->where(['sid' => $sid])->one();
     $models = Page::find()->select(['id', 'pid', 'sid', 'header'])->asArray()->indexBy('id')->all();
     $mode = $models[$model->id];
     $branch[] = $mode;
     while (!is_null($mode['pid'])) {
         $mode = $models[$mode['pid']];
         $branch[] = $mode;
     }
     krsort($branch);
     $db = Yii::$app->db;
     $current_menu = $db->createCommand('call current_menu(:sid)')->bindValue(':sid', $model->sid)->queryAll();
     $current_menu = Tree::level($current_menu, $model->pid);
     return $this->render('view', ['model' => $model, 'current_menu' => $current_menu, 'branch' => $branch]);
 }
示例#2
0
 /**
  * Deletes an existing Page model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     if (!$model->delete()) {
         // echo "<pre>";
         // print_r($model->getErrors());
         // die;
         $errors = $model->getErrors();
         $pageList = Page::find()->select(['id', 'pid', 'header'])->asArray()->all();
         $pageList = Tree::level($pageList);
         return $this->render('index', ['pageList' => $pageList, 'errors' => $errors]);
     } else {
         return $this->redirect(['index']);
     }
 }