PHP Class yii\widgets\Breadcrumbs

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 specifies the links to be displayed. For example, php $this is the view object currently being used echo Breadcrumbs::widget([ 'itemTemplate' => "
  • {link}
  • \n", // template for all links 'links' => [ [ 'label' => 'Post Category', 'url' => ['post-category/view', 'id' => 10], 'template' => "
  • {link}
  • \n", // template for this link only ], ['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]], 'Edit', ], ]);
    Because breadcrumbs usually appears in nearly every page of a website, you may consider placing it in a layout view. You can 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: php $this is the view object currently being used echo Breadcrumbs::widget([ 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], ]);
    Since: 2.0
    Author: Qiang Xue ([email protected])
    Inheritance: extends yii\base\Widget
    显示文件 Open project: yiisoft/yii2 Class Usage Examples

    Public Properties

    Property Type Description
    $activeItemTemplate 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.
    $encodeLabels whether to HTML-encode the link labels.
    $homeLink the first hyperlink in the breadcrumbs (called home link). Please refer to [[links]] on the format of the link. 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.
    $itemTemplate 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.
    $links 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: php [ 'label' => 'label of the link', // required 'url' => 'url of the link', // optional, will be processed by Url::to() 'template' => 'own template of the item', // optional, if not set $this->itemTemplate will be used ] If a link is active, you only need to specify its "label", and instead of writing ['label' => $label], you may simply use $label. Since version 2.0.1, any additional array elements for each link will be treated as the HTML attributes for the hyperlink tag. For example, the following link specification will generate a hyperlink with CSS class external: php [ 'label' => 'demo', 'url' => 'http://example.com', 'class' => 'external', ] Since version 2.0.3 each individual link can override global [[encodeLabels]] param like the following: php [ 'label' => 'Hello!', 'encode' => false, ]
    $options the HTML attributes for the breadcrumb container tag.
    $tag the name of the breadcrumb container tag.

    Public Methods

    Method Description
    run ( ) Renders the widget.

    Protected Methods

    Method Description
    renderItem ( array $link, string $template ) : string Renders a single breadcrumb item.

    Method Details

    renderItem() protected method

    Renders a single breadcrumb item.
    protected renderItem ( array $link, string $template ) : string
    $link array the link to be rendered. It must contain the "label" element. The "url" element is optional.
    $template string the template to be used to rendered the link. The token "{link}" will be replaced by the link.
    return string the rendering result

    run() public method

    Renders the widget.
    public run ( )

    Property Details

    $activeItemTemplate public_oe property

    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

    $encodeLabels public_oe property

    whether to HTML-encode the link labels.
    public $encodeLabels

    $itemTemplate public_oe property

    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

    $options public_oe property

    the HTML attributes for the breadcrumb container tag.
    See also: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
    public $options

    $tag public_oe property

    the name of the breadcrumb container tag.
    public $tag