PHP Class yii\bootstrap\Nav

For example: php echo Nav::widget([ 'items' => [ [ 'label' => 'Home', 'url' => ['site/index'], 'linkOptions' => [...], ], [ 'label' => 'Dropdown', 'items' => [ ['label' => 'Level 1 - Dropdown A', 'url' => '#'], '
  • ', '', ['label' => 'Level 1 - Dropdown B', 'url' => '#'], ], ], [ 'label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest ], ], 'options' => ['class' =>'nav-pills'], // set this to nav-tab to get tab-styled navigation ]);
    Note: Multilevel dropdowns beyond Level 1 are not supported in Bootstrap 3.
    See also: http://getbootstrap.com/components/#dropdowns
    See also: http://getbootstrap.com/components/#nav
    Since: 2.0
    Author: Antonio Ramirez ([email protected])
    Inheritance: extends yii\bootstrap\Widget
    Show file Open project: yiisoft/yii2-bootstrap Class Usage Examples

    Public Properties

    Property Type Description
    $activateItems whether to automatically activate items according to whether their route setting matches the currently requested route.
    $activateParents whether to activate parent menu items when one of the corresponding child menu items is active.
    $dropDownCaret this property allows you to customize the HTML which is used to generate the drop down caret symbol, which is displayed next to the button text to indicate the drop down functionality. Defaults to null which means will be used. To disable the caret, set this property to be an empty string.
    $dropdownClass name of a class to use for rendering dropdowns withing this widget. Defaults to Dropdown.
    $encodeLabels whether the nav items labels should be HTML-encoded.
    $items list of items in the nav widget. Each array element represents a single menu item which can be either a string or an array with the following structure: - label: string, required, the nav item label. - url: optional, the item's URL. Defaults to "#". - visible: boolean, optional, whether this menu item is visible. Defaults to true. - linkOptions: array, optional, the HTML attributes of the item's link. - options: array, optional, the HTML attributes of the item container (LI). - active: boolean, optional, whether the item should be on active state or not. - dropDownOptions: array, optional, the HTML options that will passed to the Dropdown widget. - items: array|string, optional, the configuration array for creating a Dropdown widget, or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus. - encode: boolean, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item. If a menu item is a string, it will be rendered directly without HTML encoding.
    $params the parameters used to determine if a menu item is active or not. If not set, it will use $_GET.
    $route the route used to determine if a menu item is active or not. If not set, it will use the route of the current request.

    Public Methods

    Method Description
    init ( ) Initializes the widget.
    renderItem ( string | array $item ) : string Renders a widget's item.
    renderItems ( ) Renders widget items.
    run ( ) Renders the widget.

    Protected Methods

    Method Description
    isChildActive ( array $items, boolean &$active ) : array Check to see if a child item is active optionally activating the parent.
    isItemActive ( array $item ) : boolean Checks whether a menu item is active.
    renderDropdown ( array $items, array $parentItem ) : string Renders the given items as a dropdown.

    Method Details

    init() public method

    Initializes the widget.
    public init ( )

    isChildActive() protected method

    Check to see if a child item is active optionally activating the parent.
    protected isChildActive ( array $items, boolean &$active ) : array
    $items array @see items
    $active boolean should the parent be active too
    return array @see items

    isItemActive() protected method

    This is done by checking if [[route]] and [[params]] match that specified in the url option of the menu item. When the url option of a menu item is specified in terms of an array, its first element is treated as the route for the item and the rest of the elements are the associated parameters. Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item be considered active.
    protected isItemActive ( array $item ) : boolean
    $item array the menu item to be checked
    return boolean whether the menu item is active

    renderDropdown() protected method

    This method is called to create sub-menus.
    Since: 2.0.1
    protected renderDropdown ( array $items, array $parentItem ) : string
    $items array the given items. Please refer to [[Dropdown::items]] for the array structure.
    $parentItem array the parent item information. Please refer to [[items]] for the structure of this array.
    return string the rendering result.

    renderItem() public method

    Renders a widget's item.
    public renderItem ( string | array $item ) : string
    $item string | array the item to render.
    return string the rendering result.

    renderItems() public method

    Renders widget items.
    public renderItems ( )

    run() public method

    Renders the widget.
    public run ( )

    Property Details

    $activateItems public property

    whether to automatically activate items according to whether their route setting matches the currently requested route.
    See also: isItemActive
    public $activateItems

    $activateParents public property

    whether to activate parent menu items when one of the corresponding child menu items is active.
    public $activateParents

    $dropDownCaret public property

    this property allows you to customize the HTML which is used to generate the drop down caret symbol, which is displayed next to the button text to indicate the drop down functionality. Defaults to null which means will be used. To disable the caret, set this property to be an empty string.
    public $dropDownCaret

    $dropdownClass public property

    name of a class to use for rendering dropdowns withing this widget. Defaults to Dropdown.
    Since: 2.0.7
    public $dropdownClass

    $encodeLabels public property

    whether the nav items labels should be HTML-encoded.
    public $encodeLabels

    $items public property

    list of items in the nav widget. Each array element represents a single menu item which can be either a string or an array with the following structure: - label: string, required, the nav item label. - url: optional, the item's URL. Defaults to "#". - visible: boolean, optional, whether this menu item is visible. Defaults to true. - linkOptions: array, optional, the HTML attributes of the item's link. - options: array, optional, the HTML attributes of the item container (LI). - active: boolean, optional, whether the item should be on active state or not. - dropDownOptions: array, optional, the HTML options that will passed to the Dropdown widget. - items: array|string, optional, the configuration array for creating a Dropdown widget, or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus. - encode: boolean, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item. If a menu item is a string, it will be rendered directly without HTML encoding.
    public $items

    $params public property

    the parameters used to determine if a menu item is active or not. If not set, it will use $_GET.
    See also: route
    See also: isItemActive
    public $params

    $route public property

    the route used to determine if a menu item is active or not. If not set, it will use the route of the current request.
    See also: params
    See also: isItemActive
    public $route