system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CBreadcrumbs

zii.widgets
继承 class CBreadcrumbs » CWidget » CBaseController » CComponent
可用自 1.1
源码 framework/zii/widgets/CBreadcrumbs.php
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 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.

公共属性

隐藏继承的属性

属性类型描述被定义在
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
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
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

公共方法

隐藏继承的方法

方法描述被定义在
__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

属性详情

activeLinkTemplate 属性 (自版本 v1.1.11 可用)
public string $activeLinkTemplate;

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.

encodeLabel 属性
public boolean $encodeLabel;

whether to HTML encode the link labels. Defaults to true.

public string $homeLink;

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.

htmlOptions 属性
public array $htmlOptions;

the HTML attributes for the breadcrumbs container tag.

inactiveLinkTemplate 属性 (自版本 v1.1.11 可用)
public string $inactiveLinkTemplate;

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.

public array $links;

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',
)

separator 属性
public string $separator;

the separator between links in the breadcrumbs. Defaults to ' » '.

tagName 属性
public string $tagName;

the tag name for the breadcrumbs container tag. Defaults to 'div'.

方法详情

run() 方法
public void run()
源码: framework/zii/widgets/CBreadcrumbs.php#108 (显示)
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.