Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
cc9b175c
Commit
cc9b175c
authored
May 28, 2013
by
Antonio Ramirez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Nav widget closes #367
parent
df616847
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
0 deletions
+138
-0
Nav.php
framework/yii/bootstrap/Nav.php
+138
-0
No files found.
framework/yii/bootstrap/Nav.php
0 → 100644
View file @
cc9b175c
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\bootstrap
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\base\ArrayHelper
;
use
yii\helpers\Html
;
/**
* Nav renders a nav HTML component.
*
* For example:
*
* ```php
* echo Nav::widget(array(
* 'items' => array(
* array(
* 'label' => 'Home',
* 'url' => '/',
* 'options' => array(...),
* 'active' => true,
* ),
* array(
* 'label' => 'Dropdown',
* 'dropdown' => array(
* array(
* 'label' => 'DropdownA',
* 'url' => '#',
* ),
* array(
* 'label' => 'DropdownB',
* 'url' => '#',
* ),
* ),
* ),
* ),
* ));
* ```
*
* @see http://twitter.github.io/bootstrap/components.html#nav
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @since 2.0
*/
class
Nav
extends
Widget
{
/**
* @var array list of items in the nav widget. Each array element represents a single
* menu item with the following structure:
*
* ```php
* array(
* // required, the menu item label.
* 'label' => 'Nav item label',
* // optional, the URL of the menu item. Defaults to "#"
* 'url'=> '#',
* // optional, the HTML options of the URL.
* 'urlOptions' => array(...),
* // optional the HTML attributes of the item container (LI).
* 'options' => array(...),
* // optional, an array of [[Dropdown]] widget items so to display a dropdown menu on the tab header.
* // important: there is an issue with sub-dropdown menus, and as of 3.0, bootstrap won't support sub-dropdown
* // @see https://github.com/twitter/bootstrap/issues/5050#issuecomment-11741727
* 'dropdown'=> array(...)
* )
* ```
*
* Optionally, you can also use a plain string instead of an array element.
*/
public
$items
=
array
();
/**
* Initializes the widget.
*/
public
function
init
()
{
$this
->
addCssClass
(
$this
->
options
,
'nav'
);
}
/**
* Renders the widget.
*/
public
function
run
()
{
echo
$this
->
renderItems
();
}
/**
* Renders widget items.
*/
public
function
renderItems
()
{
$items
=
array
();
foreach
(
$this
->
items
as
$item
)
{
$items
[]
=
$this
->
renderItem
(
$item
);
}
return
Html
::
tag
(
'ul'
,
implode
(
"
\n
"
,
$items
),
$this
->
options
);
}
/**
* Renders a widget's item.
* @param mixed $item the item to render.
* @return string the rendering result.
* @throws InvalidConfigException
*/
public
function
renderItem
(
$item
)
{
if
(
is_string
(
$item
))
{
return
$item
;
}
if
(
!
isset
(
$item
[
'label'
]))
{
throw
new
InvalidConfigException
(
"The 'label' option is required."
);
}
$label
=
$item
[
'label'
];
$url
=
ArrayHelper
::
getValue
(
$item
,
'url'
,
'#'
);
$options
=
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
());
$urlOptions
=
ArrayHelper
::
getValue
(
$item
,
'urlOptions'
,
array
());
$dropdown
=
null
;
// does it has a dropdown widget?
if
(
isset
(
$item
[
'dropdown'
]))
{
$urlOptions
[
'data-toggle'
]
=
'dropdown'
;
$this
->
addCssClass
(
$options
,
'dropdown'
);
$this
->
addCssClass
(
$urlOptions
,
'dropdown-toggle'
);
$label
.=
' '
.
Html
::
tag
(
'b'
,
''
,
array
(
'class'
=>
'caret'
));
$dropdown
=
Dropdown
::
widget
(
array
(
'items'
=>
$item
[
'dropdown'
],
'clientOptions'
=>
false
));
}
return
Html
::
tag
(
'li'
,
Html
::
a
(
$label
,
$url
,
$urlOptions
)
.
$dropdown
,
$options
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment