* @link http://www.yiiframework.com/ * @copyright 2008-2013 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CBreadcrumbs displays a list of links indicating the position of the current page in the whole website. * * 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 CBreadcrumbs, one usually needs to configure its {@link links} property, which specifies * the links to be displayed. For example, * *
* $this->widget('zii.widgets.CBreadcrumbs', array(
* 'links'=>array(
* 'Sample post'=>array('post/view', 'id'=>12),
* 'Edit',
* ),
* ));
*
*
* Because breadcrumbs usually appears in nearly every page of a website, the widget is better to be placed
* in a layout view. One can define a property "breadcrumbs" in the base controller class and assign it to the widget
* in the layout, like the following:
*
*
* $this->widget('zii.widgets.CBreadcrumbs', array(
* 'links'=>$this->breadcrumbs,
* ));
*
*
* Then, in each view script, one only needs to assign the "breadcrumbs" property as needed.
*
* @author Qiang Xue
* array(
* 'Sample post'=>array('post/view', 'id'=>12),
* 'Edit',
* )
*
*/
public $links=array();
/**
* @var string String, specifies how each active item is rendered. Defaults to
* "{label}", 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
*/
public $activeLinkTemplate='{label}';
/**
* @var string String, specifies how each inactive item is rendered. Defaults to
* "{label}", where "{label}" will be replaced by the corresponding item label.
* Note that inactive template does not have "{url}" parameter.
* @since 1.1.11
*/
public $inactiveLinkTemplate='{label}';
/**
* @var string the separator between links in the breadcrumbs. Defaults to ' » '.
*/
public $separator=' » ';
/**
* Renders the content of the portlet.
*/
public function run()
{
if(empty($this->links))
return;
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$links=array();
if($this->homeLink===null)
$links[]=CHtml::link(Yii::t('zii','Home'),Yii::app()->homeUrl);
elseif($this->homeLink!==false)
$links[]=$this->homeLink;
foreach($this->links as $label=>$url)
{
if(is_string($label) || is_array($url))
$links[]=strtr($this->activeLinkTemplate,array(
'{url}'=>CHtml::normalizeUrl($url),
'{label}'=>$this->encodeLabel ? CHtml::encode($label) : $label,
));
else
$links[]=str_replace('{label}',$this->encodeLabel ? CHtml::encode($url) : $url,$this->inactiveLinkTemplate);
}
echo implode($this->separator,$links);
echo CHtml::closeTag($this->tagName);
}
}