/** * 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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'category_id' => $this->category_id, 'enabled' => $this->enabled, 'sort_num' => $this->sort_num]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'target', $this->target])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'thumb', $this->thumb]); 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, 'root' => $this->root, 'lft' => $this->lft, 'rgt' => $this->rgt, 'pid' => $this->pid, 'level' => $this->level, 'if_show' => $this->if_show, 'sort' => $this->sort]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'pic', $this->pic])->andFilterWhere(['like', 'position', $this->position])->andFilterWhere(['like', 'memo', $this->memo]); return $dataProvider; }
<?php use yii\helpers\Html; use source\core\widgets\ActiveForm; use source\modules\menu\models\Menu; use source\libs\Common; use source\libs\Constants; use source\libs\TreeHelper; /* @var $this yii\web\View */ /* @var $model source\models\Menu */ /* @var $form yii\widgets\ActiveForm */ $category = $model->category_id; $taxonomies = Menu::getArrayTree($category); $options = TreeHelper::buildTreeOptionsForSelf($taxonomies, $model); ?> <?php $this->toolbars([Html::a('返回', ['index', 'category' => $category], ['class' => 'btn btn-xs btn-primary mod-site-save'])]); ?> <?php $form = ActiveForm::begin(); ?> <div class="da-form-row"> <label>父结点</label> <div class="da-form-item small"> <?php echo Html::activeHiddenInput($model, 'category_id'); ?> <select type="text" id="menu-parent_id" class="form-control" name="Menu[parent_id]"> <?php
/** * 得到菜单项 * @param type $id * @return type */ public static function getMenu($id = null) { if ($id === null) { $model = Menu::find()->all(); } else { $model = Menu::findOne(['id' => $id]); } return $model; }
public static function getMenuHtml($category, $parentId) { return Menu::getMenuHtml($category, 0); }
<!-- Content --> <div id="da-content"> <!-- Container --> <div class="da-container clearfix"> <!-- Sidebar --> <div id="da-sidebar-separator"></div> <div id="da-sidebar"> <!-- Main Navigation --> <div id="da-main-nav" class="da-button-container"> <ul> <?php echo Menu::getAdminMenu(); ?> </ul> </div> </div> <!-- Main Content Wrapper --> <div id="da-content-wrap" class="clearfix"> <!-- Content Area --> <div id="da-content-area"> <?php if (LuLu::getViewParam('defaultLayout') === null) { ?> <div class="grid_4">
public function renderMenu($category = 'main', $parentId = 0) { echo \source\modules\menu\models\Menu::getMenuHtml($category, 0); }
public function beforeDelete() { Menu::deleteAll(['category_id' => $this->id]); return true; }
/** * Finds the Menu model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $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('The requested page does not exist.'); } }
use source\LsYii; use common\widgets\TreeView; use source\modules\menu\models\Menu; /* @var $this yii\web\View */ /* @var $searchModel source\models\search\MenuSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = '菜单管理'; $this->registerJs("\$(function(){\n \$('.nav-tabs .active').mouseover(function(){\n \$(this).find('.attribute-remove').show();\n }).mouseout(function(){\n \$(this).find('.attribute-remove').hide();\n });\n \$('.nav-tabs .active .attribute-remove').click(function(){\n window.open('" . \source\helpers\Url::to(['/menu/site/delete', 'id' => $model->id]) . "' , '_self');\n return false;\n });\n})", \source\core\back\BackView::POS_END); echo source\libs\Message::getMessage(); ?> <div class="page-header"> <h3> <strong><?php echo Html::encode($this->title); ?> </strong> <div class="pull-right"> <?php echo Html::a('<span class="glyphicon glyphicon-plus"></span> ' . LsYii::gT('添加新菜单'), ['/menu/site/create'], ['class' => 'btn btn-primary']); ?> </div> </h3> </div> <div class="menu-index"> <?php echo yii\bootstrap\Tabs::widget(['items' => Menu::getItems($model->id, '/menu/site/index')]); echo TreeView::widget(['data' => Menu::getTreeData($model->root, $model->id, true, false, ['updateUrl' => '/menu/site/update', 'addChildrenUrl' => '/menu/site/create', 'deleteUrl' => '/menu/site/delete'])]); ?> </div>
/* @var $this yii\web\View */ /* @var $model common\models\Menu */ /* @var $form yii\widgets\ActiveForm */ $this->registerJsFile(Resource::getAdminUrl('/default/js/bootstrap-smartsearch.js'), ['depends' => 'yii\\web\\YiiAsset']); ?> <div class="menu-form"> <?php $form = ActiveForm::begin(['id' => 'menu-form', 'options' => ['class' => 'form-horizontal']]); ?> <?php $disabeld = $model->isNewRecord ? false : true; ?> <?php echo $form->field($model, 'pid')->textInput(['class' => 'form-control', 'autocomplete' => 'off', 'data-provide' => "smartsearch", 'data-items' => "all", 'data-source' => Menu::getToJson(), 'data-value' => $model->pid, 'disabled' => $disabeld]); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'url')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'if_show')->radioList(Constants::getMenuStatus()); ?> <?php