The main property of Menu is [[items]], which specifies the possible items in the menu. A menu item can contain sub-items which specify the sub-menu under that menu item. Menu checks the current route and request parameters to toggle certain menu items with active state. Note that Menu only renders the HTML tags about the menu. It does do any styling. You are responsible to provide CSS styles to make it look like a real menu. The following example shows how to use Menu: php echo Menu::widget([ 'items' => [ Important: you need to specify url as 'controller/action', not just as 'controller' even if default action is used. ['label' => 'Home', 'url' => ['site/index']], 'Products' menu item will be selected as long as the route is 'product/index' ['label' => 'Products', 'url' => ['product/index'], 'items' => [ ['label' => 'New Arrivals', 'url' => ['product/index', 'tag' => 'new']], ['label' => 'Most Popular', 'url' => ['product/index', 'tag' => 'popular']], ]], ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest], ], ]);
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Widget
Ejemplo n.º 1
1
 /**
  * @inheritdoc
  */
 public function run()
 {
     $items = [['label' => 'Основные', 'url' => ['/user/settings/profile']], ['label' => 'Уведомления', 'url' => ['/user/settings/notifications']]];
     echo '<nav class="menu">';
     echo '<h3 class="menu-heading">Разделы настроек</h3>';
     echo Menu::widget(['items' => $items, 'itemOptions' => ['class' => 'menu-item'], 'activeCssClass' => 'selected']);
     echo "</nav>";
 }
Ejemplo n.º 2
0
 /**
  * Renders the menu.
  */
 public function run()
 {
     // Get Module list
     $modules = array_keys(Yii::$app->modules);
     // Get sub menu for each module
     foreach ($modules as $moduleName) {
         // Get module
         $moduleObj = Yii::$app->getModule($moduleName);
         $iconClass = isset($moduleObj->iconClass) ? $moduleObj->iconClass : 'fa-dashboard';
         // Get menu
         if (property_exists($moduleObj, 'backendMenu')) {
             $getModule = Yii::$app->request->get('module');
             $item = ['label' => Icon::show($iconClass) . '<span class="nav-label">' . Yii::t($moduleName, ucfirst($moduleName)) . '</span>', 'url' => ['/' . $moduleName . '/default']];
             if (Yii::$app->controller->module->id == $moduleName and empty($getModule) or $getModule == $moduleName) {
                 $item['active'] = TRUE;
             }
             $backendMenu = $moduleObj->backendMenu;
             if (is_array($backendMenu)) {
                 foreach ($backendMenu as $itemMenu) {
                     if (isset($itemMenu['access']) and $this->checkAccess($itemMenu['access'])) {
                         $item['items'][] = ['label' => $itemMenu['label'], 'url' => $itemMenu['url']];
                     }
                 }
                 if (isset($item['items']) and !empty($item['items'])) {
                     $item['label'] .= '<span class="fa arrow"></span>';
                 }
             }
             // assign to $this->items
             $this->items[] = $item;
         }
     }
     parent::run();
 }
Ejemplo n.º 3
0
 protected function isItemActive($item)
 {
     if ($item['url'] == Url::to('')) {
         return true;
     } elseif (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
         $route = $item['url'][0];
         if ($route[0] !== '/' && Yii::$app->controller) {
             $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
         }
         if (ltrim($route, '/') !== $this->route) {
             return false;
         }
         unset($item['url']['#']);
         if (count($item['url']) > 1) {
             $params = $item['url'];
             unset($params[0]);
             foreach ($params as $name => $value) {
                 if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                     return false;
                 }
             }
         }
         return true;
     } else {
         return parent::isItemActive($item);
     }
 }
Ejemplo n.º 4
0
 protected function isItemActive($item)
 {
     if (is_string($item['url'])) {
         return $item['url'] === Yii::$app->request->url;
     } else {
         return parent::isItemActive($item);
     }
 }
Ejemplo n.º 5
0
 public function __construct($config = array())
 {
     parent::__construct($config);
     $categories = Category::find()->all();
     foreach ($categories as $category) {
         $this->items[] = ['label' => $category->caption, 'url' => ['/product/category/' . $category->machine_name]];
     }
 }
Ejemplo n.º 6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     echo $this->beforeWidget;
     if ($this->title) {
         echo $this->beforeTitle . $this->title . $this->afterTitle;
     }
     echo Menu::widget(['items' => [['label' => 'Site Admin', 'url' => Yii::$app->urlManagerBack->baseUrl, 'visible' => !Yii::$app->user->isGuest], ['label' => 'Login', 'url' => Yii::$app->urlManagerBack->createUrl(['/site/login']), 'visible' => Yii::$app->user->isGuest], ['label' => 'Logout', 'url' => Yii::$app->urlManager->createUrl(['/site/logout']), 'visible' => !Yii::$app->user->isGuest, 'template' => '<a href="{url}" data-method="post">{label}</a>'], ['label' => 'WritesDown.com', 'url' => 'http://www.writesdown.com/']]]);
     echo $this->afterWidget;
 }
Ejemplo n.º 7
0
    /**
     * @see https://github.com/yiisoft/yii2/issues/8064
     */
    public function testTagOption()
    {
        $output = Menu::widget(['route' => 'test/test', 'params' => [], 'encodeLabels' => true, 'options' => ['tag' => false], 'items' => [['label' => 'item1', 'url' => '#', 'options' => ['tag' => 'div']], ['label' => 'item2', 'url' => '#', 'options' => ['tag' => false]]]]);
        $this->assertEqualsWithoutLE(<<<HTML
<div><a href="#">item1</a></div>
<a href="#">item2</a>
HTML
, $output);
    }
Ejemplo n.º 8
0
 /**
  * Initializes the menu widget.
  * This method mainly normalizes the {@link items} property.
  * If this method is overridden, make sure the parent implementation is invoked.
  */
 public function init()
 {
     parent::init();
     $this->options['role'] = 'menu';
     if (isset($this->options['class'])) {
         $this->options['class'] .= ' page-sidebar-menu';
     } else {
         $this->options['class'] = 'page-sidebar-menu';
     }
 }
Ejemplo n.º 9
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $sortBy = Yii::$app->request->get('sort_by', 'new');
     $items[] = ['label' => 'Активные', 'url' => Url::current(['sort_by' => 'new']), 'active' => $sortBy == 'new', 'options' => ['title' => 'Темы отсортированные по времени последнего сообщения']];
     $items[] = ['label' => 'Без ответов', 'url' => Url::current(['sort_by' => 'unanwser']), 'active' => $sortBy == 'unanwser', 'options' => ['title' => 'Темы отсортированные по времени последнего сообщения и не содержащие ответов']];
     if (!Yii::$app->getUser()->getIsGuest()) {
         $items[] = ['label' => 'Мои', 'url' => Url::current(['sort_by' => 'own']), 'active' => $sortBy == 'own', 'options' => ['title' => 'Темы отсортированные по времени последнего сообщения и не содержащие ответов']];
     }
     return Menu::widget(['items' => $items, 'options' => ['class' => 'question-list-tabs']]);
 }
Ejemplo n.º 10
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     echo Html::beginTag('div', ['class' => 'page-sidebar-wrapper']);
     echo Html::beginTag('div', ['class' => 'page-sidebar navbar-collapse collapse']);
     echo Menu::widget(['items' => $this->items, 'encodeLabels' => false, 'options' => ['class' => 'page-sidebar-menu', 'data-keep-expanded' => "false", 'data-auto-scroll' => "true", 'data-slide-speed' => 200], 'submenuTemplate' => "\n<ul class=\"sub-menu\">\n{items}\n</ul>\n"]);
     echo Html::endTag('div');
     // page-sidebar-wrapper
     echo Html::endTag('div');
     // page-sidebar
 }
Ejemplo n.º 11
0
 /**
  * @inheritdoc
  */
 protected function renderItem($item)
 {
     $renderedItem = parent::renderItem($item);
     if (isset($item['badge'])) {
         $badgeOptions = ArrayHelper::getValue($item, 'badgeOptions', []);
         Html::addCssClass($badgeOptions, 'label pull-right');
     } else {
         $badgeOptions = null;
     }
     return strtr($renderedItem, ['{icon}' => isset($item['icon']) ? new Icon($item['icon'], ArrayHelper::getValue($item, 'iconOptions', [])) : '', '{badge}' => (isset($item['badge']) ? Html::tag('small', $item['badge'], $badgeOptions) : '') . (isset($item['items']) && count($item['items']) > 0 ? new Icon('fa fa-angle-left pull-right') : '')]);
 }
Ejemplo n.º 12
0
 public function init()
 {
     parent::init();
     AffixAsset::register($this->getView());
     $this->activateParents = true;
     $this->submenuTemplate = "\n<ul class='nav'>\n{items}\n</ul>\n";
     $this->linkTemplate = '<a href="{url}">{icon}{label}</a>';
     $this->labelTemplate = '{icon}{label}';
     Html::addCssClass($this->options, 'nav kv-nav');
     Html::addCssClass($this->container, 'kv-sidebar hidden-print-affix');
 }
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     if ($this->route === null && Yii::$app->controller !== null) {
         $this->route = Yii::$app->controller->getRoute();
     }
     if ($this->params === null) {
         $this->params = $_GET;
     }
     Html::addCssClass($this->options, 'nav');
 }
Ejemplo n.º 14
0
 /**
  *
  */
 public function init()
 {
     parent::init();
     foreach ($this->items as $i => &$item) {
         if (isset($item['url'])) {
             if (isset($item['items'])) {
                 // Menu
                 $item['options'] = isset($item['options']) ? $item['options'] : [];
                 Html::addCssClass($item['options'], 'treeview');
                 if (!isset($item['icon'])) {
                     $item['icon'] = $this->defaultMenuIcon;
                 }
                 // Submenu
                 foreach ($item['items'] as $j => &$subItem) {
                     if (isset($subItem['icon'])) {
                         $subItem['label'] = "{$subItem['icon']} {$subItem['label']}";
                     } else {
                         $subItem['label'] = "{$this->subLinkIcon} {$subItem['label']}";
                     }
                     if (isset($subItem['items'])) {
                         $subItem['options'] = isset($subItem['options']) ? $subItem['options'] : [];
                         Html::addCssClass($subItem['options'], 'treeview');
                         foreach ($subItem['items'] as $k => &$subSubItem) {
                             if (isset($subSubItem['icon'])) {
                                 $subSubItem['label'] = "{$subSubItem['icon']} {$subSubItem['label']}";
                             } else {
                                 $subSubItem['label'] = "{$this->subLinkIcon} {$subSubItem['label']}";
                             }
                         }
                     }
                 }
             } else {
                 // Link
                 if (!isset($item['icon'])) {
                     $item['icon'] = $this->defaultLinkIcon;
                 }
                 if (isset($item['badge'])) {
                     $label = $item['badge']['content'];
                     $type = isset($item['badge']['type']) ? $item['badge']['type'] : $this->defaultBadgeType;
                     $item['badge'] = "<small class=\"label pull-right {$type}\">{$label}</small>";
                 } else {
                     $item['badge'] = '';
                 }
             }
             // Icon
             $item['label'] = "{$item['icon']} <span>{$item['label']}</span>";
         } else {
             // Label
             $item['options'] = isset($item['options']) ? $item['options'] : [];
             Html::addCssClass($item['options'], 'header');
         }
     }
 }
Ejemplo n.º 15
0
 /**
  * Renders the content of a menu item.
  * Note that the container and the sub-menus are not rendered here.
  * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item.
  * @return string the rendering result
  */
 protected function renderItem($item)
 {
     if ($this->showIcon && isset($item['url'])) {
         if (!strpos($item['label'], '</i>')) {
             $item['label'] = strtr($this->iconTemplate, ['{icon}' => isset($item['icon']) ? $item['icon'] : $this->defaultIcon, '{label}' => $item['label']]);
         }
     }
     if (isset($item['items'])) {
         $item['label'] .= $this->showCountSubmenu ? strtr($this->countSubmenuTemplate, ['{count}' => count($item['items'])]) : '<i class="fa fa-angle-left pull-right"></i>';
     }
     return parent::renderItem($item);
 }
Ejemplo n.º 16
0
 public function init()
 {
     if ($this->renderCategories) {
         $categories = Category::findAll(['parent_id' => $this->categoryId, 'show' => true]);
         $this->items = array_merge($this->items, $this->handleCategories($categories));
     }
     if ($this->renderArticles) {
         $articles = Article::find()->where(['category_id' => $this->categoryId, 'show' => true])->orderBy(['position' => SORT_ASC])->all();
         $this->items = array_merge($this->items, $this->handleArticles($articles));
     }
     parent::init();
 }
Ejemplo n.º 17
0
 /**
  * Checks whether a menu item is active.
  * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
  * When the `url` option of a menu item is specified in terms of an array, its first element is treated
  * as the route for the item and the rest of the elements are the associated parameters.
  * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
  * be considered active.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     if (isset($item['urlActive']) && is_array($item['urlActive'])) {
         foreach ($item['urlActive'] as $auxUrl) {
             $auxItem = $item;
             $auxItem['url'] = $auxUrl;
             if (parent::isItemActive($auxItem)) {
                 return true;
             }
         }
     }
     return parent::isItemActive($item);
 }
Ejemplo n.º 18
0
 public function init()
 {
     parent::init();
     $category = Category::findOne(83);
     $descendants = $category->children()->all();
     $menuItems = [];
     foreach ($descendants as $key => $value) {
         $menuItems[] = ['label' => $value->name, 'url' => ['post/index', 'id' => $value->id]];
     }
     $menuItems[] = ['label' => '未分类', 'url' => ['post/index', 'id' => 0]];
     echo '<h4 class="text-right">分类</h4>';
     echo Menu::widget(['options' => ['class' => 'side-menu list-unstyled'], 'items' => $menuItems, 'encodeLabels' => false]);
 }
Ejemplo n.º 19
0
 /**
  * Renders the menu.
  */
 public function run()
 {
     $this->options = ['tag' => 'ul', 'class' => 'nav navbar-nav navbar-right'];
     $this->encodeLabels = false;
     $this->items[] = ['label' => \Yii::t('app', 'Home'), 'url' => [DummyModel::getHomeRoute()]];
     /** @var ArticleCategory[] $categories */
     $categories = ArticleCategory::find()->from(['t' => ArticleCategory::tableName()])->joinWith(['articles'], true, 'RIGHT JOIN')->andWhere(['t.published' => 1])->orderBy('t.position DESC, t.id')->groupBy('t.id')->all();
     \Yii::$app->params['categoryModels'] = $categories;
     foreach ($categories as $category) {
         $this->items[] = ['label' => $category->label, 'url' => [ArticleCategory::getIndexRoute(), 'alias' => $category->alias]];
     }
     parent::run();
 }
Ejemplo n.º 20
0
 /**
  * Renders the menu.
  */
 public function run()
 {
     $controller = \Yii::$app->controller;
     $moduleObj = $controller->module;
     $paths = [];
     $moduleId = isset($moduleObj->id) ? $moduleObj->id : false;
     if ($moduleId && in_array($moduleId, ['fin', 'net', 'jar', 'oef'])) {
         $paths[] = $moduleId;
     }
     $paths[] = $controller->id;
     $this->objectId = isset($controller->objectId) ? $controller->objectId : false;
     $this->pathPattern = '/^\\/' . implode('\\/', $paths) . '\\/.*$/';
     parent::run();
 }
Ejemplo n.º 21
0
    public function testEncodeLabel()
    {
        $output = Menu::widget(['route' => 'test/test', 'params' => [], 'encodeLabels' => true, 'items' => [['encode' => false, 'label' => '<span class="glyphicon glyphicon-user"></span> Users', 'url' => '#'], ['encode' => true, 'label' => 'Authors & Publications', 'url' => '#']]]);
        $this->assertEquals(<<<HTML
<ul><li><a href="#"><span class="glyphicon glyphicon-user"></span> Users</a></li>
<li><a href="#">Authors &amp; Publications</a></li></ul>
HTML
, $output);
        $output = Menu::widget(['route' => 'test/test', 'params' => [], 'encodeLabels' => false, 'items' => [['encode' => false, 'label' => '<span class="glyphicon glyphicon-user"></span> Users', 'url' => '#'], ['encode' => true, 'label' => 'Authors & Publications', 'url' => '#']]]);
        $this->assertEquals(<<<HTML
<ul><li><a href="#"><span class="glyphicon glyphicon-user"></span> Users</a></li>
<li><a href="#">Authors &amp; Publications</a></li></ul>
HTML
, $output);
    }
Ejemplo n.º 22
0
 public function init()
 {
     parent::init();
     if ($this->slug == null) {
         throw new InvalidConfigException("slug不能为空");
     }
     $this->currentAbsoluteUrl = \Yii::$app->getRequest()->getAbsoluteUrl();
     $collection = Menu::findBySlug($this->slug);
     $createCallbacks = Hook::trigger(\hass\menu\Module::EVENT_MENU_LINK_CREATE)->parameters;
     $this->items = NestedSetsTree::generateTree($collection, function ($item) use($createCallbacks) {
         list($item['label'], $item["url"]) = call_user_func($createCallbacks[$item['module']], $item['name'], $item['original']);
         $item["options"] = Serializer::unserializeToArray($item["options"]);
         return $item;
     }, 'items');
 }
Ejemplo n.º 23
0
 public function init()
 {
     parent::init();
     $this->_initOptions();
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = [__CLASS__, $this->items];
         if (($this->items = $this->cache->get($cacheKey)) === false) {
             $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items');
             $this->cache->set($cacheKey, $this->items, $this->cacheDuration, $this->cacheDependency);
         }
     } else {
         $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items');
     }
 }
Ejemplo n.º 24
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     parent::run();
     $view = $this->getView();
     $id = $this->options['id'];
     if ($this->clientOptions !== false) {
         $options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);
         $js = "jQuery('#{$id}').menu({$options});";
         $view->registerJs($js);
     }
     if (!empty($this->clientEvents)) {
         $js = [];
         foreach ($this->clientEvents as $event => $handler) {
             $js[] = "jQuery('#{$id}').on('menu{$event}', {$handler});";
         }
         $view->registerJs(implode("\n", $js));
     }
 }
Ejemplo n.º 25
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     // add css class 'sidebar-menu'
     if (isset($this->options['class'])) {
         if (is_array($this->options['class']) && !in_array('sidebar-menu', $this->options['class'])) {
             $this->options['class'][] = 'sidebar-menu';
         } elseif (false === strpos($this->options['class'], 'sidebar-menu')) {
             $this->options['class'] .= ' sidebar-menu';
         }
     } else {
         $this->options['class'] = 'sidebar-menu';
     }
     // add first header item
     if (!empty($this->header)) {
         $this->items = ArrayHelper::merge([['label' => $this->header, 'options' => ['class' => 'header']]], $this->items);
     }
 }
Ejemplo n.º 26
0
 protected function normalizeItems($items, &$active)
 {
     $currentUrl = ltrim(P::$app->getRequest()->getUrl(), '/');
     $langList = [];
     foreach (P::$app->getLocale()->enableLocales as $lang) {
         if ($lang !== P::$app->getLocale()->defaultLocale) {
             $langList[] = $lang;
         }
     }
     foreach ($items as $i => $item) {
         if (!isset($item['lang'])) {
             throw new InvalidConfigException('The "lang" element is required for each item.');
         }
         if (in_array($item['lang'], $langList)) {
             $items[$i]['url'] = '/' . $item['lang'] . '/' . $currentUrl;
         } else {
             $items[$i]['url'] = $currentUrl;
         }
     }
     return parent::normalizeItems($items, $active);
 }
Ejemplo n.º 27
0
    public function run()
    {
        if (!Yii::$app->user->isGuest) {
            ?>
            <div class="left_col scroll-view">

                <div class="navbar nav_title" style="border: 0;padding:15px 10px 15px 0;">
                    <a href="http://<?php 
            echo $_SERVER['HTTP_HOST'];
            ?>
" class="site_title">
                        GIICMS
                    </a>
                    <a href="http://<?php 
            echo $_SERVER['HTTP_HOST'];
            ?>
" class="site_title site_title_sm">
                        GIICMS
                    </a>
                </div>
                <div class="clearfix"></div>


                <!-- sidebar menu -->
                <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">

                    <div class="menu_section ">
                        <?php 
            echo Menu::widget(['items' => [['label' => '<i class="fa fa-tachometer"></i> Trang chủ', 'url' => ['site/index']], ['label' => '<i class="fa fa-thumb-tack"></i> Quản lý bài viết<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Danh mục', 'url' => ['category/index']], ['label' => 'Thêm mới danh mục', 'url' => ['category/create']], ['label' => 'Danh sách', 'url' => ['post/index']], ['label' => 'Thêm mới', 'url' => ['post/create']]]], ['label' => '<i class="fa fa fa-thumb-tack"></i> Quản lý sản phẩm<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Danh mục', 'url' => ['productcategory/index']], ['label' => 'Thêm mới danh mục', 'url' => ['productcategory/create']], ['label' => 'Danh sách', 'url' => ['product/index']], ['label' => 'Thêm mới', 'url' => ['product/create']]]], ['label' => '<i class="fa fa-shopping-cart"></i> Quản lý đơn hàng', 'url' => ['order/index']], ['label' => '<i class="fa fa-clipboard"></i> Quản lý trang<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Danh sách', 'url' => ['page/index']], ['label' => 'Thêm mới', 'url' => ['page/create']]]], ['label' => '<i class="fa fa-wrench"></i> Quản lý chung<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Menus', 'url' => ['menu/index']], ['label' => 'Files', 'url' => ['file/index']]]], ['label' => '<i class="fa fa-user"></i> Quản lý users<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Danh sách', 'url' => ['user/index']], ['label' => 'Thêm mới', 'url' => ['user/create']]]], ['label' => '<i class="fa fa-share-alt-square"></i> Phân quyền<span class="fa fa-chevron-down"></span>', 'url' => 'javascript:void(0)', 'items' => [['label' => 'Assignments', 'url' => ['assignment/index']], ['label' => 'Roles', 'url' => ['role/index']], ['label' => 'Permissions', 'url' => ['permission/index']], ['label' => 'Routes', 'url' => ['route/index']]]], ['label' => '<i class="fa fa-cog"></i> Cấu hình chung', 'url' => ['setting/index']]], 'encodeLabels' => false, 'submenuTemplate' => "\n<ul class='nav child_menu' style='display: none'>\n{items}\n</ul>\n", 'options' => array('class' => 'side-menu nav')]);
            ?>

                    </div>


                </div>

            </div>
            <?php 
        }
    }
Ejemplo n.º 28
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (strtolower($this->position) == 'header') {
         if (!Yii::$app->user->isGuest) {
             $user = Yii::$app->user->identity;
             $avatar = \cebe\gravatar\Gravatar::widget(['email' => $user->email, 'options' => ['alt' => '', 'class' => 'avatar', 'width' => 24, 'height' => 24], 'defaultImage' => 'retro', 'size' => 24]);
             $items[] = ['label' => $avatar . Yii::$app->user->identity->username, 'url' => ['/user/default/view', 'id' => Yii::$app->user->id], 'options' => ['class' => 'navbar-nav-profile']];
         }
         if (Yii::$app->user->isGuest) {
             $items[] = ['label' => 'Регистрация', 'url' => ['/user/identity/registration']];
             $items[] = ['label' => 'Вход', 'url' => ['/user/identity/login']];
         } else {
             $items[] = ['label' => 'Выход', 'url' => ['/user/identity/logout']];
         }
         return Menu::widget(['items' => $items, 'encodeLabels' => false, 'options' => ['class' => 'navbar-nav']]);
     } elseif (strtolower($this->position) == 'sub_header') {
         $items[] = ['label' => 'Последние темы', 'url' => ['/topic/default/list']];
         if (!Yii::$app->getUser()->getIsGuest()) {
             $id = Yii::$app->getUser()->getIdentity()->id;
             $notifications = UserMention::countByUser($id);
             if ($notifications > 0) {
                 $items[] = ['label' => 'Уведомления <span class="counter">' . $notifications . '</span>', 'url' => ['/notify/default/view']];
             } else {
                 $items[] = ['label' => 'Уведомления', 'url' => ['/notify/default/view']];
             }
         }
         $items[] = ['label' => 'Пользователи', 'url' => ['/user/default/list']];
         if (!Yii::$app->getUser()->getIsGuest()) {
             $items[] = ['label' => 'Создать тему', 'url' => ['/topic/default/create']];
         }
         return Menu::widget(['items' => $items, 'encodeLabels' => false, 'options' => ['class' => 'sub-navbar-nav']]);
     } elseif (strtolower($this->position) == 'footer') {
         $items = [['label' => 'Правила пользования', 'url' => ['/frontend/default/terms']], ['label' => '&bull;'], ['label' => 'Обратная связь', 'url' => ['/frontend/default/feedback']]];
         return Menu::widget(['encodeLabels' => false, 'items' => $items]);
     }
     return null;
 }
Ejemplo n.º 29
0
                </div>
              </li>
            </ul>
          </li>
        </ul>
      </div>

    </nav>
  </header>
  <!-- Left side column. contains the logo and sidebar -->
  <aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- sidebar menu: : style can be found in sidebar.less -->
        <?php 
echo Menu::widget(['encodeLabels' => false, 'options' => ['class' => 'sidebar-menu'], 'items' => [['label' => '<i class="fa fa-list-alt"></i> <span>Блог</span>', 'url' => ['/blog/post/index']], ['label' => '<i class="fa fa-file-text"></i> <span>Cтраницы</span>', 'url' => ['/page/index']], ['label' => '<i class="fa fa-image"></i> <span>Галереи</span>', 'url' => ['/gallery/index']], ['label' => '<i class="fa fa-user"></i> <span>Пользователи</span>', 'url' => ['/user/index']], ['label' => '<i class="fa fa-cog"></i> <span>Настройки</span>', 'url' => ['/setting/index']]]]);
?>
    </section>
    <!-- /.sidebar -->
  </aside>
<div class="content-wrapper">
 <!-- Content Header (Page header) -->
    <section class="content-header">
        <?php 
if (isset($this->params['header'])) {
    ?>
            <h1><?php 
    echo $this->params['header'];
    ?>
</h1>
        <?php 
Ejemplo n.º 30
0
<?php

/* @var $this \yii\web\View */
/* @var $content string */
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\Menu;
$menuItems[] = ['label' => 'Izveštaj stanja', 'url' => [$user->username . '/finances'], 'options' => ['class' => Yii::$app->controller->getRoute() == 'user/finances' ? 'active' : null]];
$menuItems[] = ['label' => 'Transakcije', 'url' => [$user->username . '/transactions'], 'options' => ['class' => Yii::$app->controller->getRoute() == 'transactions/index' ? 'active' : null]];
$menuItems[] = ['label' => 'Načini plaćanja', 'url' => [$user->username . '/payments'], 'options' => ['class' => Yii::$app->controller->getRoute() == 'user-payments/index' ? 'active' : null]];
$menuItems[] = ['label' => 'Uplata sredstava', 'url' => ['/site/deposit'], 'options' => ['class' => Yii::$app->controller->getRoute() == 'site/deposit' ? 'active' : null]];
$menuItems[] = ['label' => 'Isplata sredstava', 'url' => ['/site/withdraw'], 'options' => ['class' => Yii::$app->controller->getRoute() == 'site/withdraw' ? 'active' : null]];
echo Menu::widget(['options' => ['class' => 'sidebar-menu'], 'encodeLabels' => false, 'items' => $menuItems]);