Exemple #1
0
 /**
  * Get page name by path
  *
  * @param $path
  * @return mixed|null
  */
 public function api_getPageNameByPath($path)
 {
     $menuItem = MenuItem::find()->where(["path" => $path])->one();
     if ($menuItem) {
         return $menuItem->label;
     } else {
         return null;
     }
 }
 /**
  * Edit menu
  * @param $id
  * @return array|string|Response
  */
 public function actionEdit($id)
 {
     $model = MenuItem::findOne($id);
     if ($model === null) {
         $this->flash('error', Yii::t('easyii', 'Not found'));
         return $this->redirect(['/admin/' . $this->module->id]);
     }
     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 item updated'));
             } else {
                 $this->flash('error', Yii::t('site', 'Update error. {0}', $model->formatErrors()));
             }
             return $this->refresh();
         }
     } else {
         return $this->render('edit', ['model' => $model]);
     }
 }
Exemple #3
0
 /**
  * Get direct children
  * @return \yii\db\ActiveQuery
  */
 public function getChildren()
 {
     return $this->hasMany(MenuItem::className(), ['parent_id' => 'menu_item_id'])->orderBy(["order_num" => SORT_ASC]);
 }
Exemple #4
0
 /**
  * Retrieve menu items
  * @return mixed
  */
 public function getMenuItems()
 {
     return $this->hasMany(MenuItem::className(), ['item_id' => 'menu_id'])->sort();
 }
Exemple #5
0
echo $this->render('_form', ['model' => $model]);
?>

<hr/>

<a class="btn btn-primary" href="<?php 
echo Url::to(['/admin/' . $module . '/menu-item/create', 'menu_id' => $model->menu_id]);
?>
">
    <?php 
echo Yii::t("site", "Add menu item");
?>
</a>

<?php 
$items = MenuItem::find()->where(['menu_id' => $model->primaryKey, 'parent_id' => 'NULL'])->orderBy(["order_num" => SORT_ASC])->all();
?>

<h2><?php 
echo Yii::t("site", "Menu items");
?>
</h2>
<?php 
if (!$items) {
    ?>
    <p><?php 
    echo Yii::t("site", "No results");
    ?>
</p>
<?php 
} else {
 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());
 }
Exemple #7
0
 /**
  * @param $id
  * @return mixed
  */
 public function actionDown($id)
 {
     MenuItem::moveDown($id);
     $success = ['swap_id' => $id];
     return $this->formatResponse($success, false);
 }
Exemple #8
0
<?php

/**
 * @var $model MenuItem
 */
use yii\easyii\modules\menu\models\MenuItem;
use kuzmiand\behaviors\multilanguage\input_widget\MultiLanguageActiveField;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$items = MenuItem::find()->where(['menu_id' => $model->menu_id, 'status' => 1])->all();
$array_items = [];
if (isset($items) && !empty($items)) {
    foreach ($items as $item) {
        $array_items[$item->menu_item_id] = '#' . $item->menu_item_id . ' ' . $item->label . ' (status' . $item->status . ') ';
    }
}
?>

<?php 
$form = ActiveForm::begin(['id' => 'menu_item_form']);
echo $form->field($model, 'label')->widget(MultiLanguageActiveField::className());
echo $form->field($model, 'path');
//= $form->field($model, 'parent_id')->dropDownList(ArrayHelper::merge(['NULL' => 'None (make root)'], ArrayHelper::map(MenuItem::find()->where(['menu_id' => $model->menu_id, 'status'=>1])->all(), 'menu_item_id', 'menu_item_id' , 'label')))
echo $form->field($model, 'parent_id')->dropDownList(ArrayHelper::merge(['NULL' => 'None (make root)'], $array_items));
echo Html::submitButton(Yii::t('easyii', 'Save'), ['class' => 'btn btn-primary']);
ActiveForm::end();