Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CBaseListView
  • CBreadcrumbs
  • CDetailView
  • CListView
  • CMenu
  • CPortlet
  • MobileActivityFeedListView
  • RecordIndexListView
  • TopicsListView
  • Overview
  • Package
  • Class
  • Tree

Class CMenu

CMenu displays a multi-level menu using nested HTML lists.

The main property of CMenu is CMenu::$items, which specifies the possible items in the menu. A menu item has three main properties: visible, active and items. The "visible" property specifies whether the menu item is currently visible. The "active" property specifies whether the menu item is currently selected. And the "items" property specifies the child menu items.

The following example shows how to use CMenu:

$this->widget('zii.widgets.CMenu', array(
    'items'=>array(
        // Important: you need to specify url as 'controller/action',
        // not just as 'controller' even if default action is used.
        array('label'=>'Home', 'url'=>array('site/index')),
        // 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
        array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
            array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
            array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
        )),
        array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
    ),
));
CComponent
Extended by CBaseController
Extended by CWidget
Extended by CMenu
Package: zii\widgets
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Jonah Turnquist <poppitypop@gmail.com>
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.1
Located at x2engine/framework/zii/widgets/CMenu.php
Methods summary
public
# init( )

Initializes the menu widget. This method mainly normalizes the CMenu::$items property. If this method is overridden, make sure the parent implementation is invoked.

Initializes the menu widget. This method mainly normalizes the CMenu::$items property. If this method is overridden, make sure the parent implementation is invoked.

Overrides

CWidget::init()
public
# run( )

Calls CMenu::renderMenu() to render the menu.

Calls CMenu::renderMenu() to render the menu.

Overrides

CWidget::run()
protected
# renderMenu( array $items )

Renders the menu items.

Renders the menu items.

Parameters

$items
array
$items menu items. Each menu item will be an array with at least two elements: 'label' and 'active'. It may have three other optional elements: 'items', 'linkOptions' and 'itemOptions'.
protected
# renderMenuRecursive( array $items )

Recursively renders the menu items.

Recursively renders the menu items.

Parameters

$items
array
$items the menu items to be rendered recursively
protected string
# renderMenuItem( array $item )

Renders the content of a menu item. Note that the container and the sub-menus are not rendered here.

Renders the content of a menu item. Note that the container and the sub-menus are not rendered here.

Parameters

$item
array
$item the menu item to be rendered. Please see CMenu::$items on what data might be in the item.

Returns

string

Since

1.1.6
protected array
# normalizeItems( array $items, string $route, boolean & $active )

Normalizes the CMenu::$items property so that the 'active' state is properly identified for every menu item.

Normalizes the CMenu::$items property so that the 'active' state is properly identified for every menu item.

Parameters

$items
array
$items the items to be normalized.
$route
string
$route the route of the current request.
$active
boolean
$active whether there is an active child menu item.

Returns

array
the normalized menu items
protected boolean
# isItemActive( array $item, string $route )

Checks whether a menu item is active. This is done by checking if the currently requested URL is generated by the 'url' option of the menu item. Note that the GET parameters not specified in the 'url' option will be ignored.

Checks whether a menu item is active. This is done by checking if the currently requested URL is generated by the 'url' option of the menu item. Note that the GET parameters not specified in the 'url' option will be ignored.

Parameters

$item
array
$item the menu item to be checked
$route
string
$route the route of the current request

Returns

boolean
whether the menu item is active
Methods inherited from CWidget
__construct(), actions(), getController(), getId(), getOwner(), getViewFile(), getViewPath(), render(), setId()
Methods inherited from CBaseController
beginCache(), beginClip(), beginContent(), beginWidget(), createWidget(), endCache(), endClip(), endContent(), endWidget(), renderFile(), renderInternal(), widget()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public array $items array()
#
list of menu items. Each menu item is specified as an array of name-value pairs. Possible option names include the following:
  • label: string, optional, specifies the menu item label. When CMenu::$encodeLabel or own encodeLabel option is true, the label will be HTML-encoded. If the label is not specified, it defaults to an empty string.
  • encodeLabel: boolean whether the label for menu item should be HTML-encoded. When this option is set, it will override the global setting CMenu::$encodeLabel. This option has been available since version 1.1.15.
  • url: string or array, optional, specifies the URL of the menu item. It is passed to CHtml::normalizeUrl() to generate a valid URL. If this is not set, the menu item will be rendered as a span text.
  • visible: boolean, optional, whether this menu item is visible. Defaults to true. This can be used to control the visibility of menu items based on user permissions.
  • items: array, optional, specifies the sub-menu items. Its format is the same as the parent items.
  • active: boolean, optional, whether this menu item is in active state (currently selected). If a menu item is active and activeClass is not empty, its CSS class will be appended with activeClass. If this option is not set, the menu item will be set active automatically when the current request is triggered by url. Note that the GET parameters not specified in the 'url' option will be ignored.
  • template: string, optional, the template used to render this menu item. When this option is set, it will override the global setting CMenu::$itemTemplate. Please see CMenu::$itemTemplate for more details. This option has been available since version 1.1.1.
  • linkOptions: array, optional, additional HTML attributes to be rendered for the link or span tag of the menu item.
  • itemOptions: array, optional, additional HTML attributes to be rendered for the container tag of the menu item.
  • submenuOptions: array, optional, additional HTML attributes to be rendered for the container of the submenu if this menu item has one. When this option is set, the CMenu::$submenuHtmlOptions property will be ignored for this particular submenu. This option has been available since version 1.1.6.
list of menu items. Each menu item is specified as an array of name-value pairs. Possible option names include the following:
  • label: string, optional, specifies the menu item label. When CMenu::$encodeLabel or own encodeLabel option is true, the label will be HTML-encoded. If the label is not specified, it defaults to an empty string.
  • encodeLabel: boolean whether the label for menu item should be HTML-encoded. When this option is set, it will override the global setting CMenu::$encodeLabel. This option has been available since version 1.1.15.
  • url: string or array, optional, specifies the URL of the menu item. It is passed to CHtml::normalizeUrl() to generate a valid URL. If this is not set, the menu item will be rendered as a span text.
  • visible: boolean, optional, whether this menu item is visible. Defaults to true. This can be used to control the visibility of menu items based on user permissions.
  • items: array, optional, specifies the sub-menu items. Its format is the same as the parent items.
  • active: boolean, optional, whether this menu item is in active state (currently selected). If a menu item is active and activeClass is not empty, its CSS class will be appended with activeClass. If this option is not set, the menu item will be set active automatically when the current request is triggered by url. Note that the GET parameters not specified in the 'url' option will be ignored.
  • template: string, optional, the template used to render this menu item. When this option is set, it will override the global setting CMenu::$itemTemplate. Please see CMenu::$itemTemplate for more details. This option has been available since version 1.1.1.
  • linkOptions: array, optional, additional HTML attributes to be rendered for the link or span tag of the menu item.
  • itemOptions: array, optional, additional HTML attributes to be rendered for the container tag of the menu item.
  • submenuOptions: array, optional, additional HTML attributes to be rendered for the container of the submenu if this menu item has one. When this option is set, the CMenu::$submenuHtmlOptions property will be ignored for this particular submenu. This option has been available since version 1.1.6.
public string $itemTemplate
#

the template used to render an individual menu item. In this template, the token "{menu}" will be replaced with the corresponding menu link or text. If this property is not set, each menu will be rendered without any decoration. This property will be overridden by the 'template' option set in individual menu items via {@items}.

the template used to render an individual menu item. In this template, the token "{menu}" will be replaced with the corresponding menu link or text. If this property is not set, each menu will be rendered without any decoration. This property will be overridden by the 'template' option set in individual menu items via {@items}.

Since

1.1.1
public boolean $encodeLabel true
#

whether the labels for menu items should be HTML-encoded. Defaults to true.

whether the labels for menu items should be HTML-encoded. Defaults to true.

public string $activeCssClass 'active'
#

the CSS class to be appended to the active menu item. Defaults to 'active'. If empty, the CSS class of menu items will not be changed.

the CSS class to be appended to the active menu item. Defaults to 'active'. If empty, the CSS class of menu items will not be changed.

public boolean $activateItems true
#

whether to automatically activate items according to whether their route setting matches the currently requested route. Defaults to true.

whether to automatically activate items according to whether their route setting matches the currently requested route. Defaults to true.

Since

1.1.3
public boolean $activateParents false
#

whether to activate parent menu items when one of the corresponding child menu items is active. The activated parent menu items will also have its CSS classes appended with CMenu::$activeCssClass. Defaults to false.

whether to activate parent menu items when one of the corresponding child menu items is active. The activated parent menu items will also have its CSS classes appended with CMenu::$activeCssClass. Defaults to false.

public boolean $hideEmptyItems true
#

whether to hide empty menu items. An empty menu item is one whose 'url' option is not set and which doesn't contain visible child menu items. Defaults to true.

whether to hide empty menu items. An empty menu item is one whose 'url' option is not set and which doesn't contain visible child menu items. Defaults to true.

public array $htmlOptions array()
#

HTML attributes for the menu's root container tag

HTML attributes for the menu's root container tag

public array $submenuHtmlOptions array()
#

HTML attributes for the submenu's container tag.

HTML attributes for the submenu's container tag.

public string $linkLabelWrapper
#

the HTML element name that will be used to wrap the label of all menu links. For example, if this property is set as 'span', a menu item may be rendered as <li><a href="url"><span>label</span></a></li> This is useful when implementing menu items using the sliding window technique. Defaults to null, meaning no wrapper tag will be generated.

the HTML element name that will be used to wrap the label of all menu links. For example, if this property is set as 'span', a menu item may be rendered as <li><a href="url"><span>label</span></a></li> This is useful when implementing menu items using the sliding window technique. Defaults to null, meaning no wrapper tag will be generated.

Since

1.1.4
public array $linkLabelWrapperHtmlOptions array()
#

HTML attributes for the links' wrap element specified in CMenu::$linkLabelWrapper.

HTML attributes for the links' wrap element specified in CMenu::$linkLabelWrapper.

Since

1.1.13
public string $firstItemCssClass
#

the CSS class that will be assigned to the first item in the main menu or each submenu. Defaults to null, meaning no such CSS class will be assigned.

the CSS class that will be assigned to the first item in the main menu or each submenu. Defaults to null, meaning no such CSS class will be assigned.

Since

1.1.4
public string $lastItemCssClass
#

the CSS class that will be assigned to the last item in the main menu or each submenu. Defaults to null, meaning no such CSS class will be assigned.

the CSS class that will be assigned to the last item in the main menu or each submenu. Defaults to null, meaning no such CSS class will be assigned.

Since

1.1.4
public string $itemCssClass
#

the CSS class that will be assigned to every item. Defaults to null, meaning no such CSS class will be assigned.

the CSS class that will be assigned to every item. Defaults to null, meaning no such CSS class will be assigned.

Since

1.1.9
Properties inherited from CWidget
$actionPrefix, $skin
Magic properties inherited from CWidget
$controller, $id, $owner, $viewPath
API documentation generated by ApiGen 2.8.0