Package | zii.widgets |
---|---|
Inheritance | class CBreadcrumbs » CWidget » CBaseController » CComponent |
Since | 1.1 |
Source Code | framework/zii/widgets/CBreadcrumbs.php |
$this->widget('zii.widgets.CBreadcrumbs', array( 'links'=>array( 'Sample post'=>array('post/view', 'id'=>12), 'Edit', ), ));
$this->widget('zii.widgets.CBreadcrumbs', array( 'links'=>$this->breadcrumbs, ));
Property | Type | Description | Defined By |
---|---|---|---|
actionPrefix | string | the prefix to the IDs of the actions. | CWidget |
activeLinkTemplate | string | String, specifies how each active item is rendered. | CBreadcrumbs |
controller | CController | Returns the controller that this widget belongs to. | CWidget |
encodeLabel | boolean | whether to HTML encode the link labels. | CBreadcrumbs |
homeLink | string | the first hyperlink in the breadcrumbs (called home link). | CBreadcrumbs |
htmlOptions | array | the HTML attributes for the breadcrumbs container tag. | CBreadcrumbs |
id | string | Returns the ID of the widget or generates a new one if requested. | CWidget |
inactiveLinkTemplate | string | String, specifies how each inactive item is rendered. | CBreadcrumbs |
links | array | list of hyperlinks to appear in the breadcrumbs. | CBreadcrumbs |
owner | CBaseController | Returns the owner/creator of this widget. | CWidget |
separator | string | the separator between links in the breadcrumbs. | CBreadcrumbs |
skin | mixed | the name of the skin to be used by this widget. | CWidget |
tagName | string | the tag name for the breadcrumbs container tag. | CBreadcrumbs |
viewPath | string | Returns the directory containing the view files for this widget. | CWidget |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CWidget |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
actions() | Returns a list of actions that are used by this widget. | CWidget |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
beginCache() | Begins fragment caching. | CBaseController |
beginClip() | Begins recording a clip. | CBaseController |
beginContent() | Begins the rendering of content that is to be decorated by the specified view. | CBaseController |
beginWidget() | Creates a widget and executes it. | CBaseController |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
createWidget() | Creates a widget and initializes it. | CBaseController |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
endCache() | Ends fragment caching. | CBaseController |
endClip() | Ends recording a clip. | CBaseController |
endContent() | Ends the rendering of content. | CBaseController |
endWidget() | Ends the execution of the named widget. | CBaseController |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getController() | Returns the controller that this widget belongs to. | CWidget |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getId() | Returns the ID of the widget or generates a new one if requested. | CWidget |
getOwner() | Returns the owner/creator of this widget. | CWidget |
getViewFile() | Looks for the view script file according to the view name. | CWidget |
getViewPath() | Returns the directory containing the view files for this widget. | CWidget |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the widget. | CWidget |
raiseEvent() | Raises an event. | CComponent |
render() | Renders a view. | CWidget |
renderFile() | Renders a view file. | CBaseController |
renderInternal() | Renders a view file. | CBaseController |
run() | Renders the content of the portlet. | CBreadcrumbs |
setId() | Sets the ID of the widget. | CWidget |
widget() | Creates a widget and executes it. | CBaseController |
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.
whether to HTML encode the link labels. Defaults to true.
the first hyperlink in the breadcrumbs (called home link). If this property is not set, it defaults to a link pointing to CWebApplication::homeUrl with label 'Home'. If this property is false, the home link will not be rendered.
the HTML attributes for the breadcrumbs container tag.
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.
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 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 homeLink separately.
array( 'Sample post'=>array('post/view', 'id'=>12), 'Edit', )
the separator between links in the breadcrumbs. Defaults to ' » '.
the tag name for the breadcrumbs container tag. Defaults to 'div'.
public void run()
|
public function run()
{
if(empty($this->links))
return;
$definedLinks = $this->links;
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$links=array();
if($this->homeLink===null)
$definedLinks=array(Yii::t('zii','Home') => Yii::app()->homeUrl)+$definedLinks;
elseif($this->homeLink!==false)
$links[]=$this->homeLink;
foreach($definedLinks 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);
}
Renders the content of the portlet.
homeLink must be in HTML anchor format
To set the homeLink attribute, use
'homeLink'=>'<a href="/rs/index.php?r=Models/index">My Models</a>',
homelink
I also had a problem with homelink but PrplHaz4's way is bad use:
'homeLink'=>CHtml::link('My home', '/'),
homeLink in HTML instead of array
As PrplHaz4 commented, the homeLink attribute should be a HTML link.
I find it very strange that all breadcrumb links can be specified using an array key/value pair, while the homeLink must be in HTML.
The description of the links attribute actually states the following about how the breadcrumb hyperlinks are created:
Each key-value pair in the array will be used to generate a hyperlink by calling CHtml::link(key, value).
I thinks setting the homeLink attribute, like the breadcrumb links are set, would be better/more logical:
'homeLink'=>array('Home'=>array('site/index')) // the last argument is an array, because you might want to specify route and params, see the next example 'homeLink'=>array('Home'=>array('site/index', 'lang'=>$model->language))
As a temporary workaround the following might be used:
'homeLink'=>CHtml::link('Home', array('site/index')) // or with action params 'homeLink'=>CHtml::link('Home', array('site/index', 'lang'=>$model->language))
Signup or Login in order to comment.