Inertia js server-side integration layer for yii2.

Maintainers

Package info

github.com/yii2-framework/inertia

pkg:composer/yii2-framework/inertia

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

dev-main / 0.1.x-dev 2026-04-02 22:35 UTC

This package is auto-updated.

Last update: 2026-04-03 19:30:21 UTC


README

Yii Framework

Inertia


PHPUnit Mutation Testing PHPStan

Inertia.js server-side integration layer for Yii2
Server-driven pages, shared props, redirects, and asset version handling without jQuery

Features

Feature Overview

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.

Package information

PHP Latest Stable Version Total Downloads

Quality code

Codecov PHPStan Level Max Super-Linter StyleCI

License

License