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
f01414ff
Commit
f01414ff
authored
May 06, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Breadcrumbs.
parent
02319b99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
21 deletions
+35
-21
ActiveForm.php
framework/widgets/ActiveForm.php
+0
-1
Breadcrumbs.php
framework/widgets/Breadcrumbs.php
+35
-20
No files found.
framework/widgets/ActiveForm.php
View file @
f01414ff
...
...
@@ -12,7 +12,6 @@ use yii\base\Widget;
use
yii\base\Model
;
use
yii\helpers\Html
;
use
yii\helpers\Json
;
use
yii\helpers\JsExpression
;
/**
* ActiveForm ...
...
...
framework/widgets/Breadcrumbs.php
View file @
f01414ff
...
...
@@ -46,10 +46,13 @@ use yii\helpers\Html;
class
Breadcrumbs
extends
Widget
{
/**
* @var array the HTML attributes for the breadcrumb container tag. The "tag" element is
* specially handled which specifies the tag name of the container element. If not set, it will default to "ul".
* @var string the name of the breadcrumb container tag.
*/
public
$options
=
array
(
'tag'
=>
'ul'
,
'class'
=>
'breadcrumb'
);
public
$tag
=
'ul'
;
/**
* @var array the HTML attributes for the breadcrumb container tag.
*/
public
$options
=
array
(
'class'
=>
'breadcrumb'
);
/**
* @var boolean whether to HTML-encode the link labels.
*/
...
...
@@ -97,27 +100,40 @@ class Breadcrumbs extends Widget
}
$links
=
array
();
if
(
$this
->
homeLink
===
null
)
{
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
Html
::
a
(
Yii
::
t
(
'yii|Home'
),
Yii
::
$app
->
homeUrl
)));
$links
[]
=
$this
->
renderItem
(
array
(
'label'
=>
Yii
::
t
(
'yii|Home'
),
'url'
=>
Yii
::
$app
->
homeUrl
,
),
$this
->
itemTemplate
);
}
elseif
(
$this
->
homeLink
!==
false
)
{
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
$this
->
homeLink
)
);
$links
[]
=
$this
->
renderItem
(
$this
->
homeLink
,
$this
->
itemTemplate
);
}
foreach
(
$this
->
links
as
$link
)
{
if
(
!
is_array
(
$link
))
{
$link
=
array
(
'label'
=>
$link
);
}
if
(
isset
(
$link
[
'label'
]))
{
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$link
[
'label'
])
:
$link
[
'label'
];
}
else
{
throw
new
InvalidConfigException
(
'The "label" element is required for each link.'
);
}
if
(
isset
(
$link
[
'url'
]))
{
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
Html
::
a
(
$label
,
$link
[
'url'
])));
}
else
{
$links
[]
=
strtr
(
$this
->
activeItemTemplate
,
array
(
'{link}'
=>
$label
));
}
$links
[]
=
$this
->
renderItem
(
$link
,
isset
(
$link
[
'url'
])
?
$this
->
itemTemplate
:
$this
->
activeItemTemplate
);
}
echo
Html
::
tag
(
$this
->
tag
,
implode
(
''
,
$links
),
$this
->
options
);
}
/**
* Renders a single breadcrumb item.
* @param array $link the link to be rendered. It must contain the "label" element. The "url" element is optional.
* @param string $template the template to be used to rendered the link. The token "{link}" will be replaced by the link.
* @return string the rendering result
* @throws InvalidConfigException if `$link` does not have "label" element.
*/
protected
function
renderItem
(
$link
,
$template
)
{
if
(
isset
(
$link
[
'label'
]))
{
$label
=
$this
->
encodeLabels
?
Html
::
encode
(
$link
[
'label'
])
:
$link
[
'label'
];
}
else
{
throw
new
InvalidConfigException
(
'The "label" element is required for each link.'
);
}
if
(
isset
(
$link
[
'url'
]))
{
return
strtr
(
$template
,
array
(
'{link}'
=>
Html
::
a
(
$label
,
$link
[
'url'
])));
}
else
{
return
strtr
(
$template
,
array
(
'{link}'
=>
$label
));
}
$tagName
=
isset
(
$this
->
options
[
'tag'
])
?
$this
->
options
[
'tag'
]
:
'ul'
;
unset
(
$this
->
options
[
'tag'
]);
echo
Html
::
tag
(
$tagName
,
implode
(
''
,
$links
),
$this
->
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