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
02319b99
Commit
02319b99
authored
May 06, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #54: Implemented Breadcrumbs.
parent
c4b04b78
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
38 deletions
+68
-38
main.php
apps/bootstrap/protected/views/layouts/main.php
+3
-0
about.php
apps/bootstrap/protected/views/site/about.php
+1
-0
contact.php
apps/bootstrap/protected/views/site/contact.php
+1
-0
login.php
apps/bootstrap/protected/views/site/login.php
+1
-0
Breadcrumbs.php
framework/widgets/Breadcrumbs.php
+62
-38
No files found.
apps/bootstrap/protected/views/layouts/main.php
View file @
02319b99
...
...
@@ -39,6 +39,9 @@ $this->registerAssetBundle('app');
<!-- /.navbar -->
</div>
<?php
$this
->
widget
(
'yii\widgets\Breadcrumbs'
,
array
(
'links'
=>
isset
(
$this
->
params
[
'breadcrumbs'
])
?
$this
->
params
[
'breadcrumbs'
]
:
array
(),
));
?>
<?php
echo
$content
;
?>
<hr>
...
...
apps/bootstrap/protected/views/site/about.php
View file @
02319b99
...
...
@@ -4,6 +4,7 @@ use yii\helpers\Html;
* @var yii\base\View $this
*/
$this
->
title
=
'About'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<h1>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</h1>
...
...
apps/bootstrap/protected/views/site/contact.php
View file @
02319b99
...
...
@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\ContactForm $model
*/
$this
->
title
=
'Contact'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<h1>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</h1>
...
...
apps/bootstrap/protected/views/site/login.php
View file @
02319b99
...
...
@@ -6,6 +6,7 @@ use yii\helpers\Html;
* @var app\models\LoginForm $model
*/
$this
->
title
=
'Login'
;
$this
->
params
[
'breadcrumbs'
][]
=
$this
->
title
;
?>
<h1>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</h1>
...
...
framework/widgets/Breadcrumbs.php
View file @
02319b99
...
...
@@ -5,13 +5,40 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\w
eb
;
namespace
yii\w
idgets
;
use
Yii
;
use
yii\base\Widget
;
use
yii\base\InvalidConfigException
;
use
yii\helpers\Html
;
/**
* Breadcrumbs displays a list of links indicating the position of the current page in the whole site hierarchy.
*
* For example, breadcrumbs like "Home / Sample Post / Edit" means the user is viewing an edit page
* for the "Sample Post". He can click on "Sample Post" to view that page, or he can click on "Home"
* to return to the homepage.
*
* To use Breadcrumbs, you need to configure its [[links]] property, which specifiesthe links to be displayed. For example,
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* 'links' => array(
* array('label' => 'Sample Post', 'url' => array('post/edit', 'id' => 1)),
* 'Edit',
* ),
* ));
* ~~~
*
* Because breadcrumbs usually appears in nearly every page of a website, you may consider place it in a layout view.
* You can then use a view parameter (e.g. `$this->params['breadcrumbs']`) to configure the links in different
* views. In the layout view, you assign this view parameter to the [[links]] property like the following:
*
* ~~~
* $this->widget('yii\widgets\Breadcrumbs', array(
* 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : array(),
* ));
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
@@ -24,77 +51,73 @@ class Breadcrumbs extends Widget
*/
public
$options
=
array
(
'tag'
=>
'ul'
,
'class'
=>
'breadcrumb'
);
/**
* @var boolean whether to HTML
encode the link labels. Defaults to true
.
* @var boolean whether to HTML
-encode the link labels
.
*/
public
$encodeLabels
=
true
;
/**
* @var string the first hyperlink in the breadcrumbs (called home link).
* If this property is not set, it
defaults to a link pointing to {@link CWebApplication::homeUrl} with label 'Home'.
* If this property is false, the home link will not be rendered.
* If this property is not set, it
will default to a link pointing to [[\yii\web\Application::homeUrl]]
*
with the label 'Home'.
If this property is false, the home link will not be rendered.
*/
public
$homeLink
;
/**
* @var array list of hyperlinks to appear in the breadcrumbs. If this property is empty,
* the widget will not render anything. Each key-value pair in the array
* will be used to generate a hyperlink by calling CHtml::link(key, value). For this reason, the key
* refers to the label of the link while the value can be a string or an array (used to
* create a URL). For more details, please refer to {@link CHtml::link}.
* If an element's key is an integer, it means the element will be rendered as a label only (meaning the current page).
*
* The following example will generate breadcrumbs as "Home > Sample post > Edit", where "Home" points to the homepage,
* "Sample post" points to the "index.php?r=post/view&id=12" page, and "Edit" is a label. Note that the "Home" link
* is specified via {@link homeLink} separately.
* @var array list of links to appear in the breadcrumbs. If this property is empty,
* the widget will not render anything. Each array element represents a single link in the breadcrumbs
* with the following structure:
*
*
<pre>
*
~~~
* array(
* '
Sample post'=>array('post/view', 'id'=>12),
* '
Edit',
* '
label' => 'label of the link', // required
* '
url' => 'url of the link', // optional, will be processed by Html::url()
* )
* </pre>
* ~~~
*
* If a link is active, you only need to specify its "label", and instead of writing `array('label' => $label)`,
* you should simply use `$label`.
*/
public
$links
=
array
();
/**
* @var string String, specifies how each active item is rendered. Defaults to
* "<a href="{url}">{label}</a>", where "{label}" will be replaced by the corresponding item
* label while "{url}" will be replaced by the URL of the item.
* @since 1.1.11
* @var string the template used to render each inactive item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each inactive item.
*/
public
$itemTemplate
=
"<li>
{
link
}
<span class=
\"
divider
\"
>/</span></li>
\n
"
;
/**
* @var string String, specifies how each inactive item is rendered. Defaults to
* "<span>{label}</span>", where "{label}" will be replaced by the corresponding item label.
* Note that inactive template does not have "{url}" parameter.
* @since 1.1.11
* @var string the template used to render each active item in the breadcrumbs. The token `{link}`
* will be replaced with the actual HTML link for each active item.
*/
public
$activeItemTemplate
=
"<li class=
\"
active
\"
>
{
link
}
</li>
\n
"
;
/**
* @var string the separator between links in the breadcrumbs. Defaults to ' » '.
*/
public
$separator
=
' » '
;
/**
* Renders the
content of the portl
et.
* Renders the
widg
et.
*/
public
function
run
()
{
if
(
!
empty
(
$this
->
links
))
{
if
(
empty
(
$this
->
links
))
{
return
;
}
$links
=
array
();
if
(
$this
->
homeLink
===
null
)
{
$links
[]
=
Html
::
a
(
Html
::
encode
(
'yii|Home'
),
Yii
::
$app
->
homeUrl
);
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
Html
::
a
(
Yii
::
t
(
'yii|Home'
),
Yii
::
$app
->
homeUrl
))
);
}
elseif
(
$this
->
homeLink
!==
false
)
{
$links
[]
=
$this
->
homeLink
;
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
$this
->
homeLink
))
;
}
foreach
(
$this
->
links
as
$link
)
{
if
(
strpos
(
$link
,
'<a'
)
!==
false
)
{
$links
[]
=
strtr
(
$this
->
itemTemplate
,
array
(
'{link}'
=>
$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}'
=>
$l
ink
));
$links
[]
=
strtr
(
$this
->
activeItemTemplate
,
array
(
'{link}'
=>
$l
abel
));
}
}
$tagName
=
isset
(
$this
->
options
[
'tag'
])
?
$this
->
options
[
'tag'
]
:
'ul'
;
unset
(
$this
->
options
[
'tag'
]);
echo
Html
::
tag
(
$tagName
,
implode
(
''
,
$
this
->
links
),
$this
->
options
);
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