3
* CBreadcrumbs class file.
5
* @author Qiang Xue <qiang.xue@gmail.com>
6
* @link http://www.yiiframework.com/
7
* @copyright Copyright © 2008-2010 Yii Software LLC
8
* @license http://www.yiiframework.com/license/
12
* CBreadcrumbs displays a list of links indicating the position of the current page in the whole website.
14
* For example, breadcrumbs like "Home > Sample Post > Edit" means the user is viewing an edit page
15
* for the "Sample Post". He can click on "Sample Post" to view that page, or he can click on "Home"
16
* to return to the homepage.
18
* To use CBreadcrumbs, one usually needs to configure its {@link links} property, which specifies
19
* the links to be displayed. For example,
22
* $this->widget('zii.widgets.CBreadcrumbs', array(
24
* 'Sample post'=>array('post/view', 'id'=>12),
30
* Because breadcrumbs usually appears in nearly every page of a website, the widget is better to be placed
31
* in a layout view. One can define a property "breadcrumbs" in the base controller class and assign it to the widget
32
* in the layout, like the following:
35
* $this->widget('zii.widgets.CBreadcrumbs', array(
36
* 'links'=>$this->breadcrumbs,
40
* Then, in each view script, one only needs to assign the "breadcrumbs" property as needed.
42
* @author Qiang Xue <qiang.xue@gmail.com>
43
* @version $Id: CBreadcrumbs.php 99 2010-01-07 20:55:13Z qiang.xue $
44
* @package zii.widgets
47
class CBreadcrumbs extends CWidget
50
* @var string the tag name for the breadcrumbs container tag. Defaults to 'div'.
52
public $tagName='div';
54
* @var array the HTML attributes for the breadcrumbs container tag.
56
public $htmlOptions=array('class'=>'breadcrumbs');
58
* @var boolean whether to HTML encode the link labels. Defaults to true.
60
public $encodeLabel=true;
62
* @var string the first hyperlink in the breadcrumbs (called home link).
63
* If this property is not set, it defaults to a link pointing to {@link CWebApplication::homeUrl} with label 'Home'.
64
* If this property is false, the home link will not be rendered.
68
* @var array list of hyperlinks to appear in the breadcrumbs. If this property is empty,
69
* the widget will not render anything. Each key-value pair in the array
70
* will be used to generate a hyperlink by calling CHtml::link(key, value). For this reason, the key
71
* refers to the label of the link while the value can be a string or an array (used to
72
* create a URL). For more details, please refer to {@link CHtml::link}.
73
* If an element's key is an integer, it means the element will be rendered as a label only (meaning the current page).
75
* The following example will generate breadcrumbs as "Home > Sample post > Edit", where "Home" points to the homepage,
76
* "Sample post" points to the "index.php?r=post/view&id=12" page, and "Edit" is a label. Note that the "Home" link
77
* is specified via {@link homeLink} separately.
81
* 'Sample post'=>array('post/view', 'id'=>12),
86
public $links=array();
88
* @var string the separator between links in the breadcrumbs. Defaults to ' » '.
90
public $separator=' » ';
93
* Renders the content of the portlet.
97
if(empty($this->links))
100
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
102
if($this->homeLink===null)
103
$links[]=CHtml::link('Home',Yii::app()->homeUrl);
104
else if($this->homeLink!==false)
105
$links[]=$this->homeLink;
106
foreach($this->links as $label=>$url)
108
if(is_string($label) || is_array($url))
109
$links[]=CHtml::link($this->encodeLabel ? CHtml::encode($label) : $label, $url);
111
$links[]='<span>'.($this->encodeLabel ? CHtml::encode($url) : $url).'</span>';
113
echo implode($this->separator,$links);
114
echo CHtml::closeTag($this->tagName);
b'\\ No newline at end of file'