# BreadcrumbLink

> Represents a Breadcrumbs item: a link of the trail, or the active item.

[API reference](/docs/api/index.md) › [Bootstrap 6](/docs/extensions/bootstrap6/reference/index.md) › [item](/docs/extensions/bootstrap6/reference/item/index.md) › BreadcrumbLink

| final readonly class | `yii2\extensions\bootstrap6\item\BreadcrumbLink` |
| --- | --- |
| Uses traits | [`ItemTrait`](/docs/extensions/bootstrap6/reference/item/itemtrait/index.md) |
| Source | [`src/item/BreadcrumbLink.php`](https://github.com/yii2-extensions/bootstrap6/blob/main/src/item/BreadcrumbLink.php#L18) |

Represents a `Breadcrumbs` item: a link of the trail, or the active item.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-active"></span>`$active` readonly constructor | `bool\|null` | Whether the item is active, or `null` to make it active when [`$url`](/docs/extensions/bootstrap6/reference/item/breadcrumblink/index.md#property-url) is `null`. Default: `null`. | `BreadcrumbLink` |
| <span id="property-encode"></span>`$encode` readonly constructor | `bool\|null` | Whether to HTML-encode [`$label`](/docs/extensions/bootstrap6/reference/item/breadcrumblink/index.md#property-label), or `null` to use `Breadcrumbs::$encodeLabels`. Default: `null`. | `BreadcrumbLink` |
| <span id="property-label"></span>`$label` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Label of the `.breadcrumb-link` element. | `BreadcrumbLink` |
| <span id="property-options"></span>`$options` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `.breadcrumb-link` element. Default: `[]`. | `BreadcrumbLink` |
| <span id="property-template"></span>`$template` readonly constructor | `string\|null` | Template of the item, where `{link}` is replaced by the rendered link, or `null` to use the widget item templates. Default: `null`. | `BreadcrumbLink` |
| <span id="property-url"></span>`$url` readonly constructor | `array<array-key, mixed>\|string\|null` | URL processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to), or `null` for no `href`. Default: `null`. | `BreadcrumbLink` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`fromArray()`](#method-fromArray) static | Creates an item from the array configuration documented in `Breadcrumbs::$links`. | `BreadcrumbLink` |
| [`to()`](#method-to) static | Creates an item. | `BreadcrumbLink` |
| [`withActive()`](#method-withActive) | Returns a copy with the given active state. | `BreadcrumbLink` |
| [`withEncode()`](#method-withEncode) | Returns a copy with the given encoding flag. | `BreadcrumbLink` |
| [`withLabel()`](#method-withLabel) | Returns a copy with the given label. | `BreadcrumbLink` |
| [`withOptions()`](#method-withOptions) | Returns a copy with the given link attributes. | `BreadcrumbLink` |
| [`withTemplate()`](#method-withTemplate) | Returns a copy with the given template. | `BreadcrumbLink` |
| [`withUrl()`](#method-withUrl) | Returns a copy with the given URL. | `BreadcrumbLink` |

## Method details

### fromArray() <span id="method-fromArray"></span>

```php
public static function fromArray(array<array-key, mixed> $config): self
```

Creates an item from the array configuration documented in `Breadcrumbs::$links`.

The `active` and `encode` keys, even `null`, make their value explicit; a `url` or `template` of another type
is ignored; every other key becomes an attribute of the link.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array<array-key, mixed>` | Item configuration. |

**Returns**

`self`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the item has no `string|Stringable` `label`.

### to() <span id="method-to"></span>

```php
public static function to(string|Stringable $label, array<array-key, mixed>|string|null $url = null): self
```

Creates an item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Link label. |
| `$url` | `array<array-key, mixed>\|string\|null` | URL processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to), or `null` for the active item. |

**Returns**

`self`

### withActive() <span id="method-withActive"></span>

```php
public function withActive(bool|null $active): self
```

Returns a copy with the given active state.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$active` | `bool\|null` |  |

**Returns**

`self`

### withEncode() <span id="method-withEncode"></span>

```php
public function withEncode(bool|null $encode): self
```

Returns a copy with the given encoding flag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$encode` | `bool\|null` |  |

**Returns**

`self`

### withLabel() <span id="method-withLabel"></span>

```php
public function withLabel(string|Stringable $label): self
```

Returns a copy with the given label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) |  |

**Returns**

`self`

### withOptions() <span id="method-withOptions"></span>

```php
public function withOptions(array<array-key, mixed> $options): self
```

Returns a copy with the given link attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array<array-key, mixed>` | HTML attributes of the link. |

**Returns**

`self`

### withTemplate() <span id="method-withTemplate"></span>

```php
public function withTemplate(string|null $template): self
```

Returns a copy with the given template.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$template` | `string\|null` |  |

**Returns**

`self`

### withUrl() <span id="method-withUrl"></span>

```php
public function withUrl(array<array-key, mixed>|string|null $url): self
```

Returns a copy with the given URL.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `array<array-key, mixed>\|string\|null` | URL processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |

**Returns**

`self`