# Link

> Link represents a link object as defined in [JSON Hypermedia API Language](https://tools.ietf.org/html/draft-kelly-json-hal-03).

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › Link

| class | `yii\web\Link` |
| --- | --- |
| Extends | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/web/Link.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/Link.php#L19) |

Link represents a link object as defined in [JSON Hypermedia API Language](https://tools.ietf.org/html/draft-kelly-json-hal-03).

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$href`](#property-href) | `string` | A URI [RFC3986](https://tools.ietf.org/html/rfc3986) or URI template [RFC6570](https://tools.ietf.org/html/rfc6570). Default: `null`. | `Link` |
| <span id="property-hreflang"></span>`$hreflang` | `string` | The language of the target resource Default: `null`. | `Link` |
| <span id="property-name"></span>`$name` | `string` | A secondary key for selecting Link Objects which share the same relation type Default: `null`. | `Link` |
| <span id="property-profile"></span>`$profile` | `string` | A URI that hints about the profile of the target resource. Default: `null`. | `Link` |
| <span id="property-templated"></span>`$templated` | `bool` | A value indicating whether [`$href`](/docs/api/yii/web/link/index.md#property-href) refers to a URI or URI template. Default: `false`. | `Link` |
| <span id="property-title"></span>`$title` | `string` | A label describing the link Default: `null`. | `Link` |
| <span id="property-type"></span>`$type` | `string` | A hint to indicate the media type expected when dereferencing the target resource Default: `null`. | `Link` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/baseobject/index.md#method-__construct) | Constructor. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`serialize()`](#method-serialize) static | Serializes a list of links into proper array format. | `Link` |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-REL_SELF"></span>`REL_SELF` | `'self'` | The self link. | `Link` |

## Property details

### $href <span id="property-href"></span>

```php
public string $href = null
```

A URI [RFC3986](https://tools.ietf.org/html/rfc3986) or URI template [RFC6570](https://tools.ietf.org/html/rfc6570).

This property is required.

## Method details

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

```php
public static function serialize(array $links): array
```

Serializes a list of links into proper array format.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$links` | `array` | The links to be serialized |

**Returns**

`array`: The proper array representation of the links.