diff --git a/backend/controllers/MenuController.php b/backend/controllers/MenuController.php index 9f33c51..56f9758 100644 --- a/backend/controllers/MenuController.php +++ b/backend/controllers/MenuController.php @@ -4,10 +4,11 @@ namespace backend\controllers; use Yii; use common\models\Menu; -use backend\models\SearchMenu; +use backend\models\MenuSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use common\models\TerminLang; /** * MenuController implements the CRUD actions for Menu model. @@ -32,7 +33,7 @@ class MenuController extends Controller */ public function actionIndex() { - $searchModel = new SearchMenu(); + $searchModel = new MenuSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ @@ -61,14 +62,33 @@ class MenuController extends Controller public function actionCreate() { $model = new Menu(); - $x = Menu::find()->all(); - if ($model->load(Yii::$app->request->post()) && $model->save()) { + $menu = yii::$app->db->createCommand(' + SELECT * + FROM `menu` + LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id + ')->queryAll(); + + + $termin = TerminLang::find()->all(); + + if ($model->load(Yii::$app->request->post())) { + + if($model->menu_pid == null) + { + $model->menu_pid = 0; + } + + + $model->save(); + + return $this->redirect(['view', 'id' => $model->menu_id]); } else { return $this->render('create', [ 'model' => $model, - 'x' => $x, + 'termin' => $termin, + 'menu' => $menu, ]); } } @@ -82,12 +102,22 @@ class MenuController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); + $menu = yii::$app->db->createCommand(' + SELECT * + FROM `menu` + LEFT JOIN `termin_lang` ON `termin_lang`.termin_id = `menu`.termin_id + ')->queryAll() + ['termin_id' => 0, 'termin_title' => 'ROOT']; + + + $termin = TerminLang::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->menu_id]); } else { return $this->render('update', [ 'model' => $model, + 'termin' => $termin, + 'menu' => $menu, ]); } } diff --git a/backend/views/menu/_form.php b/backend/views/menu/_form.php index c945c0d..1c439c5 100644 --- a/backend/views/menu/_form.php +++ b/backend/views/menu/_form.php @@ -3,6 +3,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; +use kartik\select2\Select2; /* @var $this yii\web\View */ /* @var $model common\models\Menu */ @@ -13,16 +14,36 @@ use yii\helpers\ArrayHelper; - field($model, 'menu_pid')->dropDownList(ArrayHelper::map($x, 'menu_id', 'menu_id')) ?> + - field($model, 'termin_id')->textInput() ?> + field($model, 'termin_id')->widget(Select2::classname(), [ + //'data' => $data, + 'language' => 'ru', + 'options' => ['placeholder' => 'под меню ...'], + 'pluginOptions' => [ + + ], + 'data' => ArrayHelper::map($termin, 'termin_id', 'termin_title'), // data as array + ]) ?> - field($model, 'show')->textInput() ?> + field($model, 'menu_pid')->widget(Select2::classname(), [ + //'data' => $data, + 'language' => 'ru', + 'options' => ['placeholder' => 'Меню родитель ...'], + 'pluginOptions' => [ + + ], + 'data' => ArrayHelper::map($menu, 'termin_id', 'termin_title'), // data as array + ]) ?> - field($model, 'sortorder')->textInput() ?> + + + field($model, 'show')->dropDownList(['1' => Yii::t('action', 'show'), '0' => Yii::t('action', 'hide')]) ?> + + field($model, 'sortorder')->dropDownList(['1' => '1', '0' => '2']) ?>
- isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> + isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/backend/views/menu/_search.php b/backend/views/menu/_search.php index 36bfdb5..ca1ce23 100644 --- a/backend/views/menu/_search.php +++ b/backend/views/menu/_search.php @@ -4,7 +4,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ -/* @var $model backend\models\SearchMenu */ +/* @var $model backend\models\MenuSearch */ /* @var $form yii\widgets\ActiveForm */ ?> @@ -30,8 +30,8 @@ use yii\widgets\ActiveForm; field($model, 'sortorder') ?>
- 'btn btn-primary']) ?> - 'btn btn-default']) ?> + 'btn btn-primary']) ?> + 'btn btn-default']) ?>
diff --git a/backend/views/menu/create.php b/backend/views/menu/create.php index c4e74bc..4253a72 100644 --- a/backend/views/menu/create.php +++ b/backend/views/menu/create.php @@ -6,8 +6,8 @@ use yii\helpers\Html; /* @var $this yii\web\View */ /* @var $model common\models\Menu */ -$this->title = 'Create Menu'; -$this->params['breadcrumbs'][] = ['label' => 'Menus', 'url' => ['index']]; +$this->title = Yii::t('app', 'Create Menu'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Menus'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> diff --git a/backend/views/menu/index.php b/backend/views/menu/index.php index 5e431a7..3c55096 100644 --- a/backend/views/menu/index.php +++ b/backend/views/menu/index.php @@ -4,10 +4,10 @@ use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ -/* @var $searchModel backend\models\SearchMenu */ +/* @var $searchModel backend\models\MenuSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ -$this->title = 'Menus'; +$this->title = Yii::t('app', 'Menus'); $this->params['breadcrumbs'][] = $this->title; ?>