/** * Edit menu * @param $id * @return array|string|Response */ public function actionEdit($id) { $model = Menu::findOne($id); $this->layout = 'menu'; if ($model === null) { $this->flash('error', Yii::t('easyii', 'Not found')); return $this->redirect(['/admin/' . $this->module->id]); } if (isset($_POST['Menu'])) { if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } else { if ($model->save()) { $this->flash('success', Yii::t('site', 'Menu updated')); } else { $this->flash('error', Yii::t('site', 'Update error. {0}', $model->formatErrors())); } return $this->refresh(); } } } else { return $this->render('edit', ['model' => $model]); } }
/** * @param $id_slug menu id or slug * @param int $parent_id * @param null $menu_id * @param null $context * @return array * @internal param array $options */ public function api_items($id_slug, $context = null, $parent_id = 0, $menu_id = null) { if ($menu_id === null) { /** @var MenuModel $menu */ $menu = MenuModel::find()->where(["slug" => $id_slug])->one(); $menu_id = $menu->menu_id; } $items = MenuItem::find()->where(['parent_id' => $parent_id, 'menu_id' => $menu_id])->status(MenuItem::STATUS_ON)->orderBy(["order_num" => SORT_ASC])->all(); $return = []; foreach ($items as $item) { $return[] = ['label' => $item->label, 'url' => $item->path, 'active' => $context->route == trim($item->path, '/'), 'items' => $this->api_items($id_slug, $context, $item->primaryKey, $menu_id)]; } return $return; }
/** * Get associated menu * @return \yii\db\ActiveQuery */ public function getMenu() { return $this->hasOne(Menu::className(), ['menu_id' => 'menu_id']); }
public function down() { $this->dropTable(models\Admin::tableName()); $this->dropTable(models\LoginForm::tableName()); $this->dropTable(models\Module::tableName()); $this->dropTable(models\Photo::tableName()); $this->dropTable(models\Setting::tableName()); $this->dropTable(Carousel::tableName()); $this->dropTable(catalog\models\Category::tableName()); $this->dropTable(catalog\models\Item::tableName()); $this->dropTable(article\models\Category::tableName()); $this->dropTable(article\models\Item::tableName()); $this->dropTable(Feedback::tableName()); $this->dropTable(File::tableName()); $this->dropTable(gallery\models\Category::tableName()); $this->dropTable(Guestbook::tableName()); $this->dropTable(News::tableName()); $this->dropTable(Page::tableName()); $this->dropTable(Subscriber::tableName()); $this->dropTable(History::tableName()); $this->dropTable(Text::tableName()); $this->dropTable(Menu::tableName()); $this->dropTable(MenuItem::tableName()); }