Inertia facade
Crenspire\Yii2Inertia\Inertia is a static facade for the inertia application component (Crenspire\Yii2Inertia\Manager). Methods marked component are also available on the component itself, e.g. Yii::$app->inertia->render().
Rendering
render()
Inertia::render(string|BackedEnum $component, array|ProvidesInertiaProperties $props = [], array $viewData = []): ResponseRenders a page: the root view on the first visit, the JSON page object on Inertia visits. Component. See pages and props.
The global helper inertia() has the same signature.
location()
Inertia::location(string|array $url): ResponseRedirects with a full page visit: 409 Conflict with X-Inertia-Location for Inertia requests, a 302 redirect otherwise. Accepts a URL or a route for Url::to(). Component.
back()
Inertia::back(string|array $fallback = ['/']): ResponseRedirects to the referrer, or to the fallback URL or route, with 303 after PUT/PATCH/DELETE. Component.
setRootView() / getRootView()
Inertia::setRootView(string $view): void
Inertia::getRootView(): stringShared data
share()
Inertia::share(string|array|ProvidesInertiaProperties $key, mixed $value = null): voidShares one prop, an array of props, or a props provider with every page. Component.
shareOnce()
Inertia::shareOnce(string $key, callable $callback): OncePropShares a once prop. Returns the prop so it can be configured (->until(), ->as()). Component.
getShared()
Inertia::getShared(?string $key = null, mixed $default = null): mixedReturns a shared prop (unevaluated, dot notation supported) or all shared props. Component.
flushShared()
Inertia::flushShared(): voidSession data
withErrors()
Inertia::withErrors(Model|array $errors, string $bag = 'default'): voidFlashes validation errors for the next rendered page. See forms and validation. Component.
flash()
Inertia::flash(string|array $key, mixed $value = null): voidFlashes data for the next rendered page. See flash data. Component.Yii::$app->inertia->getFlashed() returns the data flashed so far.
clearHistory()
Inertia::clearHistory(): voidClears the encrypted history on the next rendered page. Component.
preserveFragment()
Inertia::preserveFragment(): voidKeeps the URL fragment of the current visit across a redirect. Component.
History
encryptHistory()
Inertia::encryptHistory(bool $encrypt = true): voidAsset versioning
version()
Inertia::version(string|int|Closure|null $version): voidSets the asset version; null restores the default.
getVersion()
Inertia::getVersion(): stringComponent.
Prop types
See prop types.
Inertia::optional(callable $callback): OptionalProp
Inertia::defer(callable $callback, string $group = 'default', bool $rescue = false): DeferProp
Inertia::always(mixed $value): AlwaysProp
Inertia::merge(mixed $value): MergeProp
Inertia::deepMerge(mixed $value): MergeProp
Inertia::once(callable $callback): OnceProp
Inertia::scroll(mixed $value, string $wrapper = 'data', ProvidesScrollMetadata|callable|null $metadata = null): ScrollPropServer-side rendering
disableSsr()
Inertia::disableSsr(bool|Closure $condition = true): voidDisables SSR, optionally based on fn (Request $request): bool.
withoutSsr()
Inertia::withoutSsr(string|array $paths): voidExcludes URL path patterns from SSR.
Root view helpers
app()
Inertia::app(array $page, ?SsrResponse $ssr = null, string $id = 'app', array $options = []): stringRenders the page data script and the root element ($options are its HTML attributes), or the server-rendered body.
ssrHead()
Inertia::ssrHead(?SsrResponse $ssr): stringRenders the head elements produced by server-side rendering, or an empty string.
vite()
Inertia::vite(): ViteReturns the Vite helper.
Utilities
isInertiaRequest()
Inertia::isInertiaRequest(?Request $request = null): boolWhether the (current) request was sent by the Inertia client. Component.
getManager()
Inertia::getManager(): ManagerReturns the inertia component, registering it with defaults when it is not configured.
Manager-only methods
createPage()
Yii::$app->inertia->createPage(string $component, array|ProvidesInertiaProperties $props = [], ?Request $request = null): arrayBuilds the page object without rendering a response.
encodePage()
Yii::$app->inertia->encodePage(array $page): stringEncodes a page object as JSON that is safe to embed in a <script> element. Throws JsonException for invalid data.
getSsrGateway() / getVite()
Return the configured SSR gateway and Vite helper instances.