public function actionDeleteMenuItem() { $id = \Yii::$app->request->post('id'); $db = \Yii::$app->getDb(); $menuItem = MenuItems::find()->where(['id' => $id])->one(); if ($menuItem != null) { $menuItem->delete(); return []; } else { throw new BusinessException("Menu item does not exist"); } }
/** * Lists all MenuItems models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => MenuItems::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
echo $form->field($model, 'name')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'url')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'menu_id')->hiddenInput(['value' => $menu_id])->label(''); ?> <div class="form-group"> <label>Родительский пункт: </label> <?php echo Html::activeDropDownList($model, 'parent_id', \yii\helpers\ArrayHelper::map(\app\models\MenuItems::find(['active' => true])->where('id != :model_id', [':model_id' => $model->id ? $model->id : 0])->andWhere('menu_id = :menu_id', [':menu_id' => $menu_id])->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => 'Выберите родительский пункт меню...']); ?> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('admin', 'Create') : Yii::t('admin', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>