Manager
API reference › Inertia › Manager
Server-side Yii adapter registered as the inertia application component.
Adapts Yii requests, application state, views, sessions, and responses to the framework-agnostic protocol core.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$clearHistory | bool | Whether rendered pages clear the client-side history. Default: false. | Manager |
$encryptHistory | bool | Whether rendered pages encrypt their client-side history state. Default: false. | Manager |
$errorFlashKey | string | Session flash key exposed as props.errors in every page payload. Default: 'errors'. | Manager |
$eventDispatcher | Psr\ | PSR-14 dispatcher the default protocol emits ProtocolResultCreated through, or null to emit no events. Default: null. | Manager |
$exposeSharedProps | bool | Whether rendered pages expose shared-prop metadata. Default: true. | Manager |
$id | string | Root element DOM id used by the default root view. Default: 'app'. | Manager |
$pageObserver | PHPForge\ | Optional portable observer notified after page resolution and before response serialization. Default: null. | Manager |
$preserveFragment | bool | Whether rendered pages preserve the URL fragment. Default: false. | Manager |
$protocol | PHPForge\ | Protocol service, or null to build the default one with $eventDispatcher. Default: null. | Manager |
$rootView | string | Root view file rendered for the initial HTML response. Default: '@inertia/views/app.php'. | Manager |
$shared | array<string, | Shared props applied to every rendered page in the current request. Default: []. | Manager |
$version | Closure(): int|Closure(yii\): int| | Asset version used for client-side mismatch detection through the page version field. Default: null. | Manager |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
flushShared() | Removes all shared props. | Manager |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getShared() | Returns all shared props or a nested value using dot notation. | Manager |
getVersion() | Resolves the configured asset version. | Manager |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the object. | yii\ |
isInertiaRequest() | Returns whether a request carries the Inertia request marker. | Manager |
location() | Returns an Inertia location response or a standard redirect response. | Manager |
normalizeResponse() | Normalizes a Yii response immediately before it is sent to an Inertia client. | Manager |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
render() | Renders an Inertia page through the framework-agnostic protocol core. | Manager |
share() | Registers props shared with subsequent page responses in the current request. | Manager |
trigger() | Triggers an event. | yii\ |
Property details
Section titled “Property details”$eventDispatcher
Section titled “$eventDispatcher ”public Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher = nullPSR-14 dispatcher the default protocol emits ProtocolResultCreated through, or null to emit no events.
Ignored when $protocol is configured. A debugger registers its collector here.
$protocol
Section titled “$protocol ”public PHPForge\Inertia\Protocol|null $protocol = nullProtocol service, or null to build the default one with $eventDispatcher.
Configure this property to inject a custom core clock for deterministic tests.
Method details
Section titled “Method details”flushShared()
Section titled “flushShared() ”public function flushShared(): voidRemoves all shared props.
getShared()
Section titled “getShared() ”public function getShared(string|null $key = null, mixed $default = null): mixedReturns all shared props or a nested value using dot notation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string| | Dot-notated key to retrieve, or null to return every shared prop. |
$default | mixed | Value returned when $key does not exist. |
Returns
mixed: Shared value at $key, or $default when the key does not exist.
getVersion()
Section titled “getVersion() ”public function getVersion(): int|stringResolves the configured asset version.
Returns
int|string: Resolved version, or an empty string when no version is configured.
isInertiaRequest()
Section titled “isInertiaRequest() ”public function isInertiaRequest(yii\web\Request|null $request = null): boolReturns whether a request carries the Inertia request marker.
Parameters
| Parameter | Type | Description |
|---|---|---|
$request | yii\| | Request to inspect, or null to use the current application request. |
Returns
bool: true when the request is Inertia-driven; otherwise, false.
location()
Section titled “location() ”public function location(array<array-key, mixed>|string $url): yii\web\ResponseReturns an Inertia location response or a standard redirect response.
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | array<array-key, | Destination URL or route array accepted by Url::to(). |
Returns
yii\web\Response: Yii response containing the protocol location or redirect result.
Throws
yii\web\BadRequestHttpException: if the request context is invalid.
normalizeResponse()
Section titled “normalizeResponse() ”public function normalizeResponse(yii\web\Response $response): voidNormalizes a Yii response immediately before it is sent to an Inertia client.
Parameters
| Parameter | Type | Description |
|---|---|---|
$response | yii\ | Outgoing Yii response to normalize. |
Throws
yii\web\BadRequestHttpException: if a redirect request context is invalid.
render()
Section titled “render() ”public function render(string $component, array<string, mixed> $props = [], array<string, mixed> $viewData = []): yii\web\ResponseRenders an Inertia page through the framework-agnostic protocol core.
Returns a JSON page payload for Inertia requests or the initial HTML document for standard browser requests.
Parameters
| Parameter | Type | Description |
|---|---|---|
$component | string | Client-side component name. |
$props | array<string, | Page-specific props. |
$viewData | array<string, | Additional data available to the initial root view. |
Returns
yii\web\Response: Yii response containing the initial HTML document or Inertia JSON page.
Throws
yii\web\BadRequestHttpException: if the request context is invalid.
share()
Section titled “share() ”public function share(array<string, mixed>|string $key, mixed $value = null): voidRegisters props shared with subsequent page responses in the current request.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | array<string, | Shared values or a dot-notated prop key. |
$value | mixed | Value registered when $key is a string. |