yii2-framework / inertia
Inertia js server-side integration layer for yii2.
Requires
- php: >=8.2
- yii2-framework/core: ^0.1@dev
Requires (Dev)
- infection/infection: ^0.32
- maglnet/composer-require-checker: ^4.1
- php-forge/coding-standard: ^0.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0.3
- phpunit/phpunit: ^10.5
- yii2-extensions/phpstan: ^0.4
This package is auto-updated.
Last update: 2026-04-03 19:30:21 UTC
README
Inertia
Inertia.js server-side integration layer for Yii2
Server-driven pages, shared props, redirects, and asset version handling without jQuery
Features
Overview
yii2-framework/inertia is the server-side base package for building modern Inertia-driven pages on top of Yii2.
It does not ship a client adapter. Instead, it defines the server contract that future packages such as
yii2-framework/inertia-vue, yii2-framework/inertia-react, and yii2-framework/inertia-svelte can reuse.
Installation
composer require yii2-framework/inertia:^0.1
Register the bootstrap class in your application configuration:
return [ 'bootstrap' => [\yii\inertia\Bootstrap::class], ];
Quick start
Render a page directly from a controller action:
use yii\inertia\Inertia; use yii\web\Controller; use yii\web\Response; final class SiteController extends Controller { public function actionIndex(): Response { return Inertia::render( 'Dashboard', ['stats' => ['visits' => 42]], ); } }
Or extend the convenience controller:
use yii\inertia\web\Controller; use yii\web\Response; final class SiteController extends Controller { public function actionIndex(): Response { return $this->inertia( 'Dashboard', [ 'stats' => ['visits' => 42], ] ); } }
Configuration example
use yii\inertia\Manager; return [ 'bootstrap' => [\yii\inertia\Bootstrap::class], 'components' => [ 'inertia' => [ 'class' => Manager::class, 'id' => 'app', 'rootView' => '@app/views/layouts/inertia.php', 'version' => static function (): string { $path = dirname(__DIR__) . '/public/build/manifest.json'; return is_file($path) ? (string) filemtime($path) : ''; }, 'shared' => ['app.name' => static fn(): string => Yii::$app->name], ], ], ];
Validation and flash messages
This package maps the session flash key errors to props.errors and exposes all remaining flashes at the top-level
flash page key. A typical validation redirect looks like this:
if (!$model->validate()) { Yii::$app->session->setFlash('errors', $model->getErrors()); return $this->redirect(['create']); } Yii::$app->session->setFlash('success', 'Record created.'); return $this->redirect(['view', 'id' => $model->id]);
Package boundaries
This repository intentionally does not include Vue, React, or Svelte bootstrapping. Those concerns belong in separate client adapter packages built on top of the server contract defined here.
Documentation
For detailed configuration options and advanced usage.
- ๐ Installation Guide
- โ๏ธ Configuration Reference
- ๐ก Usage Examples
- ๐งช Testing Guide