本文整理汇总了PHP中yii\widgets\Menu类的典型用法代码示例。如果您正苦于以下问题:PHP Menu类的具体用法?PHP Menu怎么用?PHP Menu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Menu类的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: run
/**
* 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();
}
示例3: 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;
}
示例4: 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);
}
示例5: 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']]);
}
示例6: 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
}
示例7: init
/**
*
*/
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');
}
}
}
示例8: 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]);
}
示例9: isItemActive
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);
}
}
示例10: isItemActive
protected function isItemActive($item)
{
if (is_string($item['url'])) {
return $item['url'] === Yii::$app->request->url;
} else {
return parent::isItemActive($item);
}
}
示例11: __construct
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]];
}
}
示例12: init
/**
* 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';
}
}
示例13: renderItem
/**
* @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') : '')]);
}
示例14: init
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');
}
示例15: init
/**
* 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');
}