本文整理汇总了PHP中yii\widgets\Menu::widget方法的典型用法代码示例。如果您正苦于以下问题:PHP Menu::widget方法的具体用法?PHP Menu::widget怎么用?PHP Menu::widget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\widgets\Menu
的用法示例。
在下文中一共展示了Menu::widget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @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>";
}
示例2:
<?php
use yii\widgets\Menu;
$permissions = Yii::$app->cache->get('rbac-permissions');
if (!$permissions) {
$permissions = Yii::$app->authManager->getPermissions();
Yii::$app->cache->set('rbac-permissions', $permissions);
}
$permissions = Yii::$app->user->identity->isSuperUser() ? $permissions : Yii::$app->authManager->getPermissionsByRole(Yii::$app->user->identity->role);
$items = [['label' => Yii::t('app', 'News'), 'url' => ['/admin/news/index'], 'visible' => array_key_exists('ACTION_AdminNews', $permissions), 'active' => in_array(Yii::$app->request->pathInfo, ['admin/news', 'admin/news/index', 'admin/news/edit'])], ['label' => Yii::t('app', 'Users'), 'url' => ['/admin/users/index'], 'visible' => array_key_exists('ACTION_AdminUsers', $permissions), 'active' => in_array(Yii::$app->request->pathInfo, ['admin/users', 'admin/users/index', 'admin/users/edit', 'admin/users/profile'])], ['label' => Yii::t('app', 'Settings'), 'url' => '#_', 'options' => ['class' => 'submenu-header'], 'visible' => array_key_exists('ACTION_AdminSettings', $permissions) || array_key_exists('ACTION_AdminRoles', $permissions), 'items' => [['label' => Yii::t('app', 'Main settings'), 'url' => ['/admin/settings/index'], 'visible' => array_key_exists('ACTION_AdminSettings', $permissions)], ['label' => Yii::t('app', 'Roles'), 'url' => ['/admin/roles/index'], 'visible' => array_key_exists('ACTION_AdminRoles', $permissions), 'active' => in_array(Yii::$app->request->pathInfo, ['admin/roles', 'admin/roles/index', 'admin/roles/edit'])]]]];
?>
<?php
echo Menu::widget(['encodeLabels' => false, 'activateParents' => true, 'submenuTemplate' => '<ul class="nav">{items}</ul>', 'items' => $items, 'options' => ['class' => 'nav sidenav', 'id' => 'menu']]);
示例3: testTagOption
/**
* @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);
}
示例4: run
/**
* @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;
}
示例5: run
/**
* 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
}
示例6: run
/**
* @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']]);
}
示例7: init
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]);
}
示例8: testEncodeLabel
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 & 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 & Publications</a></li></ul>
HTML
, $output);
}
示例9: run
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
}
}
示例10: run
/**
* @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' => '•'], ['label' => 'Обратная связь', 'url' => ['/frontend/default/feedback']]];
return Menu::widget(['encodeLabels' => false, 'items' => $items]);
}
return null;
}
示例11:
} else {
?>
<?php
echo Yii::t('app', 'Hi');
?>
,
<span class="dropdown">
<a href="<?php
echo \yii\helpers\Url::toRoute(['user/user/profile']);
?>
" class="link-cabinet" data-toggle="dropdown" data-hover="dropdown"><?php
echo Html::encode(Yii::$app->user->identity->username);
?>
</a>!
<?php
echo \yii\widgets\Menu::widget(['items' => [['label' => Yii::t('app', 'User profile'), 'url' => ['/user/user/profile'], ['class' => 'user-profile-link']], ['label' => Yii::t('app', 'Logout'), 'url' => ['/user/user/logout'], ['data-action' => 'post', 'class' => 'logout-link']]], 'options' => ['class' => 'dropdown-menu personal-menu']]);
?>
</span>
<?php
}
?>
</div>
<div class="pull-right search-area">
<?php
echo \app\extensions\DefaultTheme\widgets\OneRowHeaderWithCart\ExpandableSearchField::widget(['useFontAwesome' => $useFontAwesome]);
?>
</div>
示例12:
<div class="user-panel">
<div class="pull-left image">
<?php
echo Html::img($baseUrl . '/img/user2-160x160.jpg', ['class' => 'img-circle', 'alt' => 'User Image']);
?>
</div>
<div class="pull-left info">
<p>Alexander Pierce</p>
<a href="#"><i class="fa fa-circle text-success"></i> Online</a>
</div>
</div>
<!-- sidebar menu: : style can be found in sidebar.less -->
<?php
//使用路由写法,能自动激活active,Yii::$app->getHomeUrl()
echo Menu::widget(['encodeLabels' => false, 'submenuTemplate' => '<ul class="treeview-menu">{items}</ul>', 'options' => ['class' => 'sidebar-menu'], 'itemOptions' => ['class' => 'treeview'], 'items' => [['label' => '<i class="fa fa-dashboard"></i><span>后台首页</span>', 'url' => ['/OrderAnalysis/default/index']], ['label' => '<i class="fa fa-cubes "></i><span>订单统计</span><i class="fa fa-angle-left pull-right"></i>', 'url' => 'javascript:;', 'items' => [['label' => '<i class="fa fa-leaf "></i><span>订单详细信息</span>', 'url' => ['/OrderAnalysis/oms-order/index']]]], ['label' => '<i class="fa fa-cubes "></i><span>买家统计</span><i class="fa fa-angle-left pull-right"></i>', 'url' => 'javascript:;', 'items' => [['label' => '<i class="fa fa-leaf "></i><span>订单详细信息</span>', 'url' => ['/OrderAnalysis/oms-order/index']]]], ['label' => '<i class="fa fa-cubes "></i><span>物流统计</span><i class="fa fa-angle-left pull-right"></i>', 'url' => 'javascript:;', 'items' => [['label' => '<i class="fa fa-leaf "></i><span>订单详细信息</span>', 'url' => ['/OrderAnalysis/oms-order/index']]]]]]);
?>
</section>
<!-- /.sidebar -->
</aside>
<!-- TODO: end left -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<?php
// 官方推荐:
// foreach (Yii::$app->getSession()->getAllFlashes() as $key => $message) {
// echo '<div class="alert alert-' . $key . '">' . $message . '</div>';
// }
if (Yii::$app->getSession()->hasFlash('danger')) {
示例13:
<?php
/**
* Created by PhpStorm.
* User: Abhimanyu
* Date: 02-03-2015
* Time: 23:33
*/
use abhimanyu\user\models\Profile;
use yii\helpers\Html;
use yii\widgets\Menu;
/** @var $profile \abhimanyu\user\models\Profile */
$profile = Profile::findOne(['uid' => Yii::$app->user->getId()]);
?>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><?php
echo Html::img(Yii::$app->homeUrl . '/../../' . $profile['avatar'], ['alt' => 'Profile Image', 'width' => 30, 'class' => 'img-rounded']);
?>
<?php
echo Html::encode($profile['name_first'] . ' ' . $profile['name_last']);
?>
</h3></div>
<div class="panel-body">
<?php
echo Menu::widget(['options' => ['class' => 'nav nav-pills nav-stacked'], 'items' => [['label' => 'Profile', 'url' => ['/user/account/profile']], ['label' => 'Avatar', 'url' => ['/user/account/avatar']]]]);
?>
</div>
</div>
示例14:
<?php
use yii\widgets\Menu;
?>
<div class="col-md-3">
<div class="panel panel-info">
<div class="panel-heading"><?php
echo \yii\helpers\Html::encode($user->username);
?>
</div>
<div class="panel-body">
<?php
echo Menu::widget(['options' => ['class' => 'nav nav-pills nav-stacked'], 'items' => [['label' => "Профиль пользователя", 'url' => ["/user/{$user->username}"], 'active' => Yii::$app->controller->action->id == 'show' ? true : false]]]);
?>
</div>
</div>
</div>
示例15:
<?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]);