# ToolbarPresenter

> Renders the debug toolbar into a page and reports the captured request through the debug response headers.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › [service](/docs/extensions/debug/reference/service/index.md) › ToolbarPresenter

| class | `yii\debug\service\ToolbarPresenter` |
| --- | --- |
| Source | [`src/service/ToolbarPresenter.php`](https://github.com/yii2-extensions/debug/blob/main/src/service/ToolbarPresenter.php#L26) |

Renders the debug toolbar into a page and reports the captured request through the debug response headers.

The caller decides whether the current request may see the toolbar; every method here assumes that decision was
already made.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-module"></span>`$module` protected readonly constructor | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the toolbar configuration at call time. | `ToolbarPresenter` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Binds toolbar presentation to the debug module. | `ToolbarPresenter` |
| [`html()`](#method-html) | Returns the toolbar HTML: a `<yii-debug-toolbar>` custom element wired with data attributes the bundled JS reads. | `ToolbarPresenter` |
| [`injectIntoErrorPage()`](#method-injectIntoErrorPage) | Rewrites the rendered HTML of an error page so it carries the toolbar and its runtime script. | `ToolbarPresenter` |
| [`render()`](#method-render) | Echoes the toolbar and its runtime script at the end of the page body. | `ToolbarPresenter` |
| [`writeDebugHeaders()`](#method-writeDebugHeaders) | Sets the tag, duration, and full-view link of the captured request on the response. | `ToolbarPresenter` |
| [`renderer()`](#method-renderer) protected | Creates the Yii2-specific toolbar renderer. | `ToolbarPresenter` |

## Method details

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

```php
public function __construct(yii\debug\Module $module)
```

Binds toolbar presentation to the debug module.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$module` | [`yii\debug\Module`](/docs/extensions/debug/reference/module/index.md) | Debug module read for the toolbar configuration at call time. |

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

```php
public function html(): string
```

Returns the toolbar HTML: a `<yii-debug-toolbar>` custom element wired with data attributes the bundled JS
reads.

**Returns**

`string`: Rendered `<yii-debug-toolbar>` element.

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the module has not been bootstrapped.

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

```php
public function injectIntoErrorPage(yii\web\ErrorHandlerRenderEvent $event): void
```

Rewrites the rendered HTML of an error page so it carries the toolbar and its runtime script.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$event` | [`yii\web\ErrorHandlerRenderEvent`](/docs/api/yii/web/errorhandlerrenderevent/index.md) | Render event carrying the error-page HTML. |

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the module has not been bootstrapped.

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

```php
public function render(yii\web\View $view): void
```

Echoes the toolbar and its runtime script at the end of the page body.

The toolbar markup is rendered dynamically, so a cached page still carries the tag of the request that served
it, while the runtime URL is resolved through the Yii2 asset manager.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$view` | [`yii\web\View`](/docs/api/yii/web/view/index.md) | View handling the current response. |

**Throws**

- [`Throwable`](https://www.php.net/manual/en/class.throwable.php): when the view dynamic render fails for the current request.

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

```php
public function writeDebugHeaders(yii\web\Response $response): void
```

Sets the tag, duration, and full-view link of the captured request on the response.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$response` | [`yii\web\Response`](/docs/api/yii/web/response/index.md) | Response about to be sent. |

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): when the module has not been bootstrapped.

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

```php
protected function renderer(yii\base\View|null $view = null): yii\debug\ToolbarRenderer
```

Creates the Yii2-specific toolbar renderer.

Override point: a subclass returning its own renderer changes the templates and the asset publisher every
method here draws the toolbar markup and its runtime script from.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$view` | [`yii\base\View`](/docs/api/yii/base/view/index.md)`\|null` | View handling the current response, or `null` to use the application view. |

**Returns**

[`yii\debug\ToolbarRenderer`](/docs/extensions/debug/reference/toolbarrenderer/index.md): Configured toolbar renderer.