继承 | yii\widgets\Breadcrumbs » yii\base\Widget » yii\base\Component » yii\base\Object |
---|---|
可用自版本 | 2.0 |
面包屑显示一个链接列表显示当前页面的位置在整个网站的层次结构.
例如,面包屑像“家/样本/编辑”意味着用户在查看一个编辑页面的“样本文章”。他可以点击“样本文章”页面查看,或者他可以点击“家”返回主页。
使用面包屑,您需要配置美元链接属性,它指定要显示的链接。例如,
// $this is the view object currently being used
echo Breadcrumbs::widget([
'itemTemplate' => "<li><i>{link}</i></li>\n", // template for all links
'links' => [
[
'label' => 'Post Category',
'url' => ['post-category/view', 'id' => 10],
'template' => "<li><b>{link}</b></li>\n", // template for this link only
],
['label' => 'Sample Post', 'url' => ['post/edit', 'id' => 1]],
'Edit',
],
]);
因为面包屑通常出现在几乎每一个页面的网站,你可能会考虑将其放置在布局视图。您可以使用一个视图参数(例如$ this - > params[“面包屑”])来配置不同的视图中的链接。在布局视图中,您将这个视图参数分配给美元的链接属性如下:
// $this is the view object currently being used
echo Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]);
公共属性
属性 | 类型 | 描述 | 定义在 |
---|---|---|---|
$activeItemTemplate | string | 模板用于呈现每个活动项目在面包屑 | yii\widgets\Breadcrumbs |
$encodeLabels | boolean | 是否HTML-encode链接标签。 | yii\widgets\Breadcrumbs |
$homeLink | array | 第一个链接面包屑(称为链接)。 | yii\widgets\Breadcrumbs |
$itemTemplate | string | 模板用于呈现每个活动项的面包屑。 | yii\widgets\Breadcrumbs |
$links | array | 出现在面包屑链接的列表。 | yii\widgets\Breadcrumbs |
$options | array | 面包屑的HTML属性容器标签。 | yii\widgets\Breadcrumbs |
$tag | string | 面包屑容器的名称标签。 | yii\widgets\Breadcrumbs |
公共方法
方法 | 描述 | 定义在 |
---|---|---|
run() | 呈现小部件. | yii\widgets\Breadcrumbs |
受保护的方法
方法 | 描述 | 定义在 |
---|---|---|
renderItem() | 呈现一个导航项。 | yii\widgets\Breadcrumbs |
属性详情
$activeItemTemplate public property
模板用于呈现每个活动项目在面包屑。令牌} {链接将被替换为实际的HTML链接,每个活动项目.
public string $activeItemTemplate = "<li class=\"active\">{link}</li>\n"
$encodeLabels public property
是否HTML-encode链接标签。
public boolean $encodeLabels = true
$homeLink public property
第一breadcrumbs hyperlink in The home(年)链接。请公约to $连结on the format of the链接。如果this property set,it is not将default to a link to特点yii\web\Application::homeUrll:label与“家”。如果is this property false,the home链接将not be新的管理。
$itemTemplate public property
模板用于呈现每个活动项的面包屑。令牌} {链接将被替换为实际的HTML链接为每个活动条目。
public string $itemTemplate = "<li>{link}</li>\n"
$links public property
出现在面包屑链接的列表。如果这个属性为空,小部件不会呈现任何东西。每个数组元素代表一个的面包屑链接下面的结构:
[
'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
]
如果一个链接是活跃的,你只需要指定它的“标签”,而不是写美元“标签”= >标签,你可以简单地使用元标签.
自版本 2.0.1,任何额外的数组元素的每个链接将被视为超链接标记的 HTML 属性。例如,下面的链接规范将生成 CSS 类外部超链接︰
[
'label' => 'demo',
'url' => 'http://example.com',
'class' => 'external',
]
从版本2.0.3每个链接可以覆盖全球美元encodeLabels参数如下:
[
'label' => '<strong>Hello!</strong>',
'encode' => false,
]
$options public property
面包屑的HTML属性容器标签。
参见 yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public array $options = ['class' => 'breadcrumb']
$tag public property
面包屑容器的名称标签。
方法详情
renderItem() protected 方法
Renders a single breadcrumb item.
protected string renderItem ( $link, $template ) | ||
$link | array | 呈现的链接。它必须包含“标签”元素。“url”元素是可选的。 |
$template | string | 模板用于呈现链接。令牌“{like}链接”将被链接所取代。 |
return | string | The rendering result |
---|---|---|
throws | yii\base\InvalidConfigException | 如果 |
run() public 方法
呈现小部件。
public void run ( ) |