本文整理汇总了PHP中yii\widgets\Menu::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Menu::init方法的具体用法?PHP Menu::init怎么用?PHP Menu::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\widgets\Menu
的用法示例。
在下文中一共展示了Menu::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->items) {
if (!$this->menu) {
throw new InvalidParamException('Menu property must be set.');
}
$class = $this->menuModelClass;
if (is_int($this->menu)) {
$this->menu = $class::findOne($this->menu);
} elseif (is_string($this->menu)) {
$this->menu = $class::findBySlug($this->menu);
}
if ($this->menu instanceof $class) {
//Get items
$this->items = $this->menu->getItems();
if ($this->beforeItems) {
$this->items = array_merge($this->beforeItems, $this->items);
}
if ($this->afterItems) {
$this->items = array_merge($this->items, $this->afterItems);
}
if (!empty($this->menu->element_id) && !isset($this->options['id'])) {
$this->options['id'] = $this->menu->element_id;
}
if (!empty($this->menu->css_class)) {
Html::addCssClass($this->options, $this->menu->css_class);
}
}
}
}
示例2: init
/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
parent::init();
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
}
}
示例3: 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';
}
}
示例4: 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');
}
示例5: 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');
}
示例6: init
/**
* Initializes this widget.
*/
public function init()
{
parent::init();
if (empty($this->items)) {
$this->items = $this->getItems();
}
$this->encodeLabels = false;
$this->activateParents = true;
$this->submenuTemplate = "\n<ul class=\"treeview-menu\">\n{items}\n</ul>\n";
$this->options = ['class' => 'sidebar-menu'];
}
示例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()
{
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();
}
示例9: init
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');
}
示例10: init
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');
}
}
示例11: init
/**
* @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);
}
}
示例12: init
public function init()
{
parent::init();
Html::addCssClass($this->options, 'iconized');
Yii::$app->view->registerCss(<<<CSS
.iconized li {
\tbackground: no-repeat 0 50%;
}
.iconized a {
\tpadding-left: 20px;
}
CSS
, [], 'samdark/IconizedMenu');
if ($this->useSprites) {
$domains = $this->fetchDomains($this->items);
$this->spriteUrl = $this->yandexBaseUrl . implode('/', $domains);
}
}
示例13: init
public function init()
{
parent::init();
SideNavAsset::register($this->getView());
$this->activateParents = true;
$this->submenuTemplate = "\n<ul class='nav nav-pills nav-stacked'>\n{items}\n</ul>\n";
$this->linkTemplate = '<a href="{url}">{icon}{label}</a>';
$this->labelTemplate = '{icon}{label}';
$this->markTopItems();
Html::addCssClass($this->options, 'nav nav-pills nav-stacked kv-sidenav');
}
示例14: init
public function init()
{
parent::init();
MenuAsset::register($this->getView());
$this->activateParents = true;
}
示例15: init
public function init()
{
$this->items = $this->item_list();
parent::init();
}