public function Principal() { $model = new Menu(); $items = $model->getItems(); $menu = ''; $n1 = $n2 = $n3 = array(); //return $this->items; foreach ($items as $n) { if ($n['nivel'] == 1) { $n1[] = $n; } } foreach ($items as $n) { if ($n['nivel'] == 2) { $n2[] = $n; } } foreach ($items as $n) { if ($n['nivel'] == 3) { $n3[] = $n; } } foreach ($n1 as $link) { $menu .= '<li data-id="' . $link['id_menu'] . '"><a href="' . $link['enlace'] . '" style="border-bottom: 2px solid #45b29d;"><span>' . $link['nombre'] . '<span class="m-d-arrow"></span></span></a>'; //segundo nivel0 if ($model->tieneHijosItems($link['id_menu'])) { $menu .= '<ul class="sub-menu">'; foreach ($n2 as $link2) { if ($link2['padre'] == $link['id_menu']) { $menu .= '<li data-id="' . $link2['id_menu'] . '" data-padre="' . $link2['padre'] . '"><a href="' . $link2['enlace'] . '">' . $link2['nombre'] . '</a>'; //tercer nivel if ($model->tieneHijosItems($link2['id_menu'])) { $menu .= '<ul class="sub-menu">'; foreach ($n3 as $link3) { if ($link3['padre'] == $link2['id_menu']) { $menu .= '<li data-id="' . $link3['id_menu'] . '" data-padre="' . $link3['padre'] . '"><a href="' . $link3['enlace'] . '">' . $link3['nombre'] . '</a>'; $menu .= '</li>'; } } //foreach 3 $menu .= '</ul>'; } //tercer nivel $menu .= '</li>'; } } // foreach 2 $menu .= '</ul>'; } //segundo nivel $menu .= '</li>'; } //foreach 1 echo $menu; }
/** * 修改菜单状态 * @param int $menu_id 菜单id * @param int $status 状态码 [0, 1] * @return bool|int */ public function setStatus($menu_id, $status = 1) { if (!in_array($status, [0, 1])) { return false; } return Menu::updateAll(['status' => $status], 'menu_id = :menu_id', [':menu_id' => $menu_id]); }
/** * @inheritdoc * @return string */ public function run() { $items = []; $menus = Menu::find()->where(['status' => Menu::STATUS_ACTIVE, 'position' => 'header'])->orderBy('order')->all(); foreach ($menus as $menu) { $items[] = ['active' => $menu->getActiveStatus(), 'label' => Yii::t('main', $menu->label), 'url' => preg_match('/\\/\\//', $menu->url) ? $menu->url : $menu->route, 'linkOptions' => ['class' => $menu->class]]; } return $this->render('header', ['items' => $items]); }
/** * Devuelve todos los enlaces * @return array enlaces */ public static function getItems() { $items = []; $subitems1 = []; $subitems2 = []; $hasN1 = $hasN2 = $hasN3 = false; $models = Menu::getMenuJerarquia(); //find()->all(); return $models; }
function printMenuTree($parent_id) { $menu = Menu::find()->where(['parent_id' => $parent_id])->orderBy('sort')->all(); foreach ($menu as $m) { echo "<li class='sortitem' data-id='{$m->id}' data-parent-id='{$m->parent_id}'><span class='sortMenuLink'>{$m->name}</span> | <a class='editMenu' data-menu-id='{$m->id}' class='sortMenuLink' href='#'>Редактировать</a> | <a data-confirm='Удалить пункт меню?' class='sortMenuLink' href='/secure/menu/menu/delete?id={$m->id}'>Удалить</a>"; echo "<ul id='sortable' class='ui-sortable'><li class='empty first'></li>"; printMenuTree($m->id); echo "<li class='empty end'></li></ul>"; echo "</li>"; } }
public static function getData() { $rows = Menu::find()->all(); $arrayData = array(); foreach ($rows as $row) { $row->imagenes = Menu::getMenuImagesById($row->id); $arrayData[$row->id] = $row->attributes + ['imagenes' => $row->imagenes]; } $jsonData = Json::encode($arrayData); return $jsonData; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'key', $this->key])->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
public function actionNodeDrop($id) { $model = Menu::findOne($id); $model->attributes = Yii::$app->request->get(); if (Yii::$app->request->get('movetype') == 'inner') { } if ($model->save()) { return $this->ok('转移成功'); } else { return $this->error('转移失败'); } }
/** * Generate menu items for yii\widgets\Menu * * @param null|array $models * @return array */ public static function getMenuItems(array $models = null) { $items = []; if ($models === null) { $models = Menu::find()->where(['parent_id' => null])->with('childs')->orderBy(['sort_index' => SORT_ASC])->active()->all(); } foreach ($models as $model) { $url = preg_match('/^(http:\\/\\/|https:\\/\\/)/', $model->url) ? $model->url : Yii::$app->request->baseurl . '/' . ltrim($model->url, '/'); $items[] = ['url' => $url, 'label' => $model->label, 'items' => self::getMenuItems($model->childs), 'active' => $model->url === Yii::$app->request->pathinfo]; } return $items; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id_menu' => $this->id_menu, 'padre' => $this->padre]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'clase', $this->clase])->andFilterWhere(['like', 'enlace', $this->enlace])->andFilterWhere(['like', 'tipo_enlace', $this->tipo_enlace])->andFilterWhere(['like', 'target', $this->target]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'type', $this->type]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); $query->joinWith(['categoria']); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'id_categoria' => $this->id_categoria, 'precio' => $this->precio, 'create_user' => $this->create_user, 'create_time' => $this->create_time, 'update_user' => $this->update_user, 'update_time' => $this->update_time]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion', $this->descripcion])->andFilterWhere(['like', 'categoria.nombre', $this->categoria]); return $dataProvider; }
public function actionEdit($id) { $model = new MenuForm(); if (!($desiredModel = Menu::find()->with('items')->where(['id' => $id])->one())) { throw new NotFoundHttpException("Не найдено меню с идентификатором {$id}!"); } $model->loadMenu($desiredModel); if (\Yii::$app->request->post('MenuForm') && $model->load(\Yii::$app->request->post())) { if ($model->save()) { \Yii::$app->session->setFlash('success', 'Меню успешно отредактировано!'); } else { \Yii::$app->session->setFlash('error', 'Произошла ошибка при редактировании меню!'); } } return $this->render('edit', ['model' => $model]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'sort' => $this->sort]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; }
/** * @param FunctionalTester $I */ public function testCreateMenu(FunctionalTester $I) { $I->wantTo('ensure that create menu works'); $indexPage = IndexPage::openBy($I); $I->see('Menus', 'h1'); $I->see('Menu Primary', 'h2'); $I->amGoingTo('submit create menu form with no menu title'); $indexPage->submitMenu(''); $I->expect('new menu not saved'); $I->seeCurrentUrlEquals(Url::to(['/menu/index'])); $I->amGoingTo('submit create menu with menu title'); $indexPage->submitMenu('Test Menu'); $I->expectTo('see new menu'); $I->dontSeeCurrentUrlEquals(Url::to(['/menu/index'])); $I->see('Test Menu', 'h2'); $I->dontSee('Menu Item Primary'); Menu::deleteAll(['title' => 'Test Menu']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Menu::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'label', $this->label])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'position', $this->position]); //$query->andFilterWhere([ // 'DATE(FROM_UNIXTIME(`created_at`))' => $this->created_at, //]); return $dataProvider; }
public function run() { if (!empty($this->position)) { $where = ['position' => $this->position, 'status' => 'on']; } else { $where = ''; } $data = Menu::find()->where($where)->orderBy('sort')->asArray()->all(); $menuView = 'menu-header-bottom'; if ($this->position == 'headerTop') { $menuView = 'menu-header-top'; } else { if ($this->position == 'headerBottom') { $menuView = 'menu-header-bottom'; } } $itemsData = $this->getItems($data); $items = $this->getSubItems($itemsData); return $this->render($menuView, ['items' => $items]); }
public function save() { if (!$this->validate()) { return false; } $model = new Menu(); if (!empty($this->id)) { $model = Menu::findOne($this->id); } $model->setAttributes(['name' => $this->name, 'alias' => $this->alias]); $isNew = $model->isNewRecord; if ($model->save(false)) { $this->id = $model->id; if (!$isNew) { $oldItems = MenuItem::find()->where(['menuID' => $this->id])->all(); $existedMenus = ArrayHelper::getColumn($oldItems, 'id'); $newItems = ArrayHelper::getColumn($this->items, 'id'); if ($needToRemoveItems = array_diff($existedMenus, $newItems)) { \Yii::trace($needToRemoveItems); foreach ($oldItems as $item) { if (in_array($item->id, $needToRemoveItems)) { $item->delete(); } } } } foreach ($this->items as $order => $menuItem) { if (!$menuItem->menuID) { $menuItem->menuID = $this->id; } if (!$menuItem->order) { $menuItem->order = $order; } $menuItem->save(); } } return !empty($this->id); }
/** * @return \yii\db\ActiveQuery */ public function getMenu() { return $this->hasOne(Menu::className(), ['id' => 'menu_id']); }
echo $form->field($model, 'active_route')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'url')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'class')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'position')->dropDownList(Menu::getMenuPosition()); ?> <?php echo $form->field($model, 'status')->dropDownList(Menu::getStatusOption()); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
echo $assetBundle->baseUrl . '/img/logo.png'; ?> " alt="Website Logo"> <span><?php echo Html::encode($siteTitle); ?> </span> </a> <?php echo Html::endTag($brandTag); ?> </div> <div id="menu-primary" class="collapse navbar-collapse"> <?php echo Nav::widget(['activateParents' => true, 'options' => ['class' => 'nav navbar-nav navbar-right'], 'items' => Menu::getMenu('primary'), 'encodeLabels' => false]); ?> </div> </div> </nav> <div id="search-breadcrumb"> <div class="container"> <div class="row"> <div class="col-md-8"> <nav id="breadcrumb-primary"> <?php echo Breadcrumbs::widget(['links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> </nav>
use common\models\Sucursal; use yii\helpers\ArrayHelper; use kartik\widgets\DateTimePicker; /* @var $this yii\web\View */ /* @var $model common\models\Promocion */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="promocion-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'id_menu')->dropDownList(ArrayHelper::map(Menu::find()->all(), 'id', 'nombre'), ['prompt' => 'Seleccione menú']); ?> <?php echo $form->field($model, 'id_sucursal')->dropDownList(ArrayHelper::map(Sucursal::find()->all(), 'id', 'nombre'), ['prompt' => 'Seleccione sucursal']); ?> <?php echo $form->field($model, 'precio')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'descripcion')->textInput(['maxlength' => true]); ?> <?php
/** * Finds the Menu model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Menu the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Menu::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php Pjax::begin(); ?> <div class="table-responsive"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'sorter' => [], 'rowOptions' => function ($model, $key, $index, $grid) { return ['data-sortable-id' => $model->id]; }, 'options' => ['data' => ['sortable-widget' => 1, 'sortable-url' => \yii\helpers\Url::toRoute(['sorting'])]], 'columns' => [['class' => Column::className()], 'label', 'url', 'position', ['attribute' => 'status', 'value' => function ($model) { return $model->statusText; }, 'filter' => \common\models\Menu::getStatusOption()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div> <?php Pjax::end(); ?> <p> <?php echo Html::a(Yii::t('app', 'Create Menu'), ['create'], ['class' => 'btn btn-success']); ?> </p> </div> <!-- Loading (remove the following to stop the loading)--> <div class="overlay grid-view-overlay hidden"> <?php
public function getAllMenu() { return Menu::find()->where(['status' => 'on'])->all(); }
<p class="action"> <?php echo Html::a('创建菜单', ['create', 'pid' => isset($_GET['pid']) ? $_GET['pid'] : 0], ['class' => 'btn btn-success']); ?> <?php if (Yii::$app->request->get('pid', 0) > 0) { echo Html::a('返回列表', ['index'], ['class' => 'btn btn-warning']); } ?> </p> </div> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn', 'name' => 'menu_id'], 'menu_id', 'title', ['header' => Html::a('子菜单', 'javascript:void(0);'), 'content' => function ($model) { $Menu = new Menu(); $count = $Menu->itemMenu($model->menu_id); if ($count > 0) { return Html::a($count, ['index', 'pid' => $model->menu_id]); } return Html::a($count, 'javascript:void(0);'); }], 'url', 'sort', ['header' => Html::a('状态', 'javascript:void(0);'), 'content' => function ($model) { if ($model->status == 1) { return Html::img('@web/image/yes.gif', ['onclick' => "setStatus(this, {$model->menu_id})", 'data-status' => 0]); } return Html::img('@web/image/no.gif', ['onclick' => "setStatus(this, {$model->menu_id})", 'data-status' => 1]); }], ['class' => 'yii\\grid\\ActionColumn', 'header' => Html::a('操作', 'javascript:void(0);'), 'template' => '{update} {delete}']]]); ?> <?php Pjax::end(); ?>
public function actionMenu() { $data = Menu::getData(); return $this->render('menu', ['$data' => $data]); }
/** * @return \yii\db\ActiveQuery */ public function getMenus() { return $this->hasMany(Menu::className(), ['id_categoria' => 'id']); }
echo Html::csrfMetaTags(); ?> <title> <?php echo $this->title; ?> </title> <?php $this->head(); ?> </head> <body> <?php $this->beginBody(); NavBar::begin(['brandLabel' => Option::get('sitetitle'), 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-static-top', 'id' => 'navbar-primary']]); echo Nav::widget(['options' => ['class' => 'navbar-nav'], 'items' => Menu::getMenu('primary'), 'encodeLabels' => false]); NavBar::end(); ?> <header id="header-primary"> <div class="container"> <?php if (Yii::$app->controller->route == 'site/index') { echo Html::tag('h1', Option::get('sitetitle'), ['id' => 'site-title', 'class' => 'site-title']); } else { echo Html::tag('span', Option::get('sitetitle'), ['id' => 'site-title', 'class' => 'h1 site-title']); } echo Html::tag('span', Option::get('tagline'), ['id' => 'site-tagline', 'class' => 'h3 site-tagline']); ?> </div> </header> <div id="breadcrumb-primary" class="hidden-xs">
/** * 修改状态 * @param int $menu_id 菜单id * @param int $status */ public function actionStatus($menu_id, $status = 1) { if (!$this->is_access('menu/update')) { exit; } $model = new Menu(); if ($model->setStatus($menu_id, $status)) { echo '1'; } else { echo '0'; } }