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
151d5d2c
Commit
151d5d2c
authored
May 31, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #469 from creocoder/menu-refactoring
\yii\widgets\Menu improvement
parents
c9a7119b
00dec2bf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
Menu.php
framework/yii/widgets/Menu.php
+19
-7
No files found.
framework/yii/widgets/Menu.php
View file @
151d5d2c
...
@@ -9,6 +9,7 @@ namespace yii\widgets;
...
@@ -9,6 +9,7 @@ namespace yii\widgets;
use
Yii
;
use
Yii
;
use
yii\base\Widget
;
use
yii\base\Widget
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
/**
/**
...
@@ -68,6 +69,13 @@ class Menu extends Widget
...
@@ -68,6 +69,13 @@ class Menu extends Widget
*/
*/
public
$items
=
array
();
public
$items
=
array
();
/**
/**
* @var array list of HTML attributes for the menu container tag. This will be overwritten
* by the "options" set in individual [[items]]. The following special options are recognized:
*
* - tag: string, defaults to "li", the tag name of the item container tags.
*/
public
$itemOptions
=
array
();
/**
* @var string the template used to render the body of a menu which is a link.
* @var string the template used to render the body of a menu which is a link.
* In this template, the token `{url}` will be replaced with the corresponding link URL;
* In this template, the token `{url}` will be replaced with the corresponding link URL;
* while `{label}` will be replaced with the link text.
* while `{label}` will be replaced with the link text.
...
@@ -110,7 +118,9 @@ class Menu extends Widget
...
@@ -110,7 +118,9 @@ class Menu extends Widget
*/
*/
public
$hideEmptyItems
=
true
;
public
$hideEmptyItems
=
true
;
/**
/**
* @var array the HTML attributes for the menu's container tag.
* @var array the HTML attributes for the menu's container tag. The following special options are recognized:
*
* - tag: string, defaults to "ul", the tag name of the item container tags.
*/
*/
public
$options
=
array
();
public
$options
=
array
();
/**
/**
...
@@ -151,7 +161,9 @@ class Menu extends Widget
...
@@ -151,7 +161,9 @@ class Menu extends Widget
$this
->
params
=
$_GET
;
$this
->
params
=
$_GET
;
}
}
$items
=
$this
->
normalizeItems
(
$this
->
items
,
$hasActiveChild
);
$items
=
$this
->
normalizeItems
(
$this
->
items
,
$hasActiveChild
);
echo
Html
::
tag
(
'ul'
,
$this
->
renderItems
(
$items
),
$this
->
options
);
$options
=
$this
->
options
;
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'ul'
);
echo
Html
::
tag
(
$tag
,
$this
->
renderItems
(
$items
),
$options
);
}
}
/**
/**
...
@@ -164,7 +176,8 @@ class Menu extends Widget
...
@@ -164,7 +176,8 @@ class Menu extends Widget
$n
=
count
(
$items
);
$n
=
count
(
$items
);
$lines
=
array
();
$lines
=
array
();
foreach
(
$items
as
$i
=>
$item
)
{
foreach
(
$items
as
$i
=>
$item
)
{
$options
=
isset
(
$item
[
'options'
])
?
$item
[
'options'
]
:
array
();
$options
=
array_merge
(
$this
->
itemOptions
,
ArrayHelper
::
getValue
(
$item
,
'options'
,
array
()));
$tag
=
ArrayHelper
::
remove
(
$options
,
'tag'
,
'li'
);
$class
=
array
();
$class
=
array
();
if
(
$item
[
'active'
])
{
if
(
$item
[
'active'
])
{
$class
[]
=
$this
->
activeCssClass
;
$class
[]
=
$this
->
activeCssClass
;
...
@@ -189,7 +202,7 @@ class Menu extends Widget
...
@@ -189,7 +202,7 @@ class Menu extends Widget
'{items}'
=>
$this
->
renderItems
(
$item
[
'items'
]),
'{items}'
=>
$this
->
renderItems
(
$item
[
'items'
]),
));
));
}
}
$lines
[]
=
Html
::
tag
(
'li'
,
$menu
,
$options
);
$lines
[]
=
Html
::
tag
(
$tag
,
$menu
,
$options
);
}
}
return
implode
(
"
\n
"
,
$lines
);
return
implode
(
"
\n
"
,
$lines
);
}
}
...
@@ -203,13 +216,13 @@ class Menu extends Widget
...
@@ -203,13 +216,13 @@ class Menu extends Widget
protected
function
renderItem
(
$item
)
protected
function
renderItem
(
$item
)
{
{
if
(
isset
(
$item
[
'url'
]))
{
if
(
isset
(
$item
[
'url'
]))
{
$template
=
isset
(
$item
[
'template'
])
?
$item
[
'template'
]
:
$this
->
linkTemplate
;
$template
=
ArrayHelper
::
getValue
(
$item
,
'template'
,
$this
->
linkTemplate
)
;
return
strtr
(
$template
,
array
(
return
strtr
(
$template
,
array
(
'{url}'
=>
Html
::
url
(
$item
[
'url'
]),
'{url}'
=>
Html
::
url
(
$item
[
'url'
]),
'{label}'
=>
$item
[
'label'
],
'{label}'
=>
$item
[
'label'
],
));
));
}
else
{
}
else
{
$template
=
isset
(
$item
[
'template'
])
?
$item
[
'template'
]
:
$this
->
labelTemplate
;
$template
=
ArrayHelper
::
getValue
(
$item
,
'template'
,
$this
->
labelTemplate
)
;
return
strtr
(
$template
,
array
(
return
strtr
(
$template
,
array
(
'{label}'
=>
$item
[
'label'
],
'{label}'
=>
$item
[
'label'
],
));
));
...
@@ -284,5 +297,4 @@ class Menu extends Widget
...
@@ -284,5 +297,4 @@ class Menu extends Widget
}
}
return
false
;
return
false
;
}
}
}
}
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