php yii-widgets-Menu类(方法)实例源码

下面列出了php yii-widgets-Menu 类(方法)源码代码实例,从而了解它的用法。

作者:marley-ph    项目:linuxforu   
/**
  * @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>";
 }

作者:quynhv    项目:stepu   
/**
  * 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();
 }

作者:tampaph    项目:app-cm   
/**
  * @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;
 }

作者:how    项目:yii   
/**
     * @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);
    }

作者:marley-ph    项目:linuxforu   
/**
  * @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']]);
 }

作者:anl    项目:yii2-metroni   
/**
  * 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
 }

作者:sacar    项目:yii2-admin-lte-   
/**
  *
  */
 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');
         }
     }
 }

作者:rocketyan    项目:dcms   
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]);
 }

作者:aivavi    项目:yii   
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);
    }

作者:rocketyan    项目:hasscms-ap   
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');
 }

作者:oakcm    项目:oakcm   
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');
     }
 }

作者:huynhtuvinh8    项目:cm   
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 
        }
    }

作者:heartshar    项目:linuxforu   
/**
  * @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;
 }

作者:eje    项目:yii2-app-advance   
</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

作者:bokko7    项目:servicemap   
<?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]);

作者:oakcm    项目:oakcm   
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);
     }
 }

作者:heartshar    项目:dotplant   
protected function isItemActive($item)
 {
     if (is_string($item['url'])) {
         return $item['url'] === Yii::$app->request->url;
     } else {
         return parent::isItemActive($item);
     }
 }

作者:AsterAI-cor    项目:categor   
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]];
     }
 }

作者:appx    项目:yii2-sideba   
/**
  * 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';
     }
 }

作者:yiiste    项目:yii2-adminlt   
/**
  * @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') : '')]);
 }


问题


面经


文章

微信
公众号

扫码关注公众号