/** * Creates a new Menu model. * If creation is successful, the browser will be redirected to the 'view' page. * @param int $top_id * @return mixed */ public function actionCreate($top_id = 0) { $model = new Menu(); if (Yii::$app->request->isPost) { $model->load(Yii::$app->request->post()); if ($top_id) { $saved = $model->prependTo(Menu::findOne($top_id)); } else { $saved = $model->makeRoot(); } if ($saved) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Menu has been created.')); return $this->redirect(ReturnUrl::getUrl()); } } else { $model->load(Yii::$app->request->get()); } return $this->render('create', compact('model')); }
/** * Deletes an existing Subdistrict model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { try { $model = $this->findModel($id); if ($model->operation->allowDelete == FALSE) { throw $model->operation->exception('delete'); } $model->delete(); } catch (\Exception $e) { $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); \Yii::$app->getSession()->setFlash('error', $msg); return $this->redirect(ReturnUrl::getUrl(Url::previous())); } // TODO: improve detection $isPivot = strstr('$id', ','); if ($isPivot == true) { return $this->redirect(ReturnUrl::getUrl(Url::previous())); } elseif (isset(\Yii::$app->session['__crudReturnUrl']) && \Yii::$app->session['__crudReturnUrl'] != '/') { Url::remember(null); $url = \Yii::$app->session['__crudReturnUrl']; $url = ReturnUrl::getUrl($url); \Yii::$app->session['__crudReturnUrl'] = null; return $this->redirect($url); } else { return $this->redirect(['index']); } }
/** * Deletes an existing Menu model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Menu has been deleted.')); return $this->redirect(ReturnUrl::getUrl(['index'])); }
<?php use yii\helpers\Html; use yii\helpers\Url; use cornernote\returnurl\ReturnUrl; /** * @var yii\web\View $this * @var frontend\modules\region\models\Subdistrict $model */ $this->title = 'Create'; $this->params['breadcrumbs'][] = ['label' => 'Region', 'url' => ['/region']]; $this->params['breadcrumbs'][] = ['label' => 'Subdistricts', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="giiant-crud subdistrict-create"> <p class="pull-left"> <?php echo Html::a('Cancel', ReturnUrl::getUrl(Url::previous()), ['class' => 'btn btn-default']); ?> </p> <div class="clearfix"></div> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
<?php use yii\helpers\Html; use cornernote\returnurl\ReturnUrl; /** * @var yii\web\View $this * @var cornernote\menu\models\Menu $model */ ?> <!-- menu buttons --> <p class='pull-left'> <?php echo Html::a('<span class="fa fa-arrow-left"></span> ' . Yii::t('app', 'Back'), ReturnUrl::getUrl(['index']), ['class' => 'btn btn-default']); ?> <?php echo Html::a('<span class="fa fa-eye"></span> ' . Yii::t('app', 'View'), ['view', 'id' => $model->id, 'ru' => ReturnUrl::getRequestToken()], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('<span class="fa fa-plus"></span> ' . Yii::t('app', 'Create') . ' ' . Yii::t('app', 'Menu'), ['top_id' => $model->id, 'create', 'ru' => ReturnUrl::getToken()], ['class' => 'btn btn-success modal-remote']); ?> <?php echo Html::a('<span class="fa fa-pencil"></span> ' . Yii::t('app', 'Update'), ['update', 'id' => $model->id, 'ru' => ReturnUrl::getRequestToken()], ['class' => 'btn btn-info']); ?> <?php echo Html::a('<span class="fa fa-trash"></span> ' . Yii::t('app', 'Delete'), ['delete', 'id' => $model->id, 'ru' => ReturnUrl::getRequestToken()], ['class' => 'btn btn-danger', 'data-confirm' => '' . Yii::t('app', 'Are you sure to delete this menu?') . '', 'data-method' => 'post']); ?> </p> <div class="clearfix"></div>