PHPackages                             yii2-extensions/inertia - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yii2-extensions/inertia

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yii2-extensions/inertia
=======================

Inertia js server-side integration layer for yii2.

0.1.0(1mo ago)31.5k[2 PRs](https://github.com/yii2-extensions/inertia/pulls)3BSD-3-ClausePHPPHP &gt;=8.3CI passing

Since Apr 16Pushed 3w agoCompare

[ Source](https://github.com/yii2-extensions/inertia)[ Packagist](https://packagist.org/packages/yii2-extensions/inertia)[ RSS](/packages/yii2-extensions-inertia/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (10)Versions (4)Used By (3)

    ![Yii Framework](https://camo.githubusercontent.com/f390171a839a7620dea19acb5fc1fb87f9226e65910c577f99803347ce48336a/68747470733a2f2f7777772e7969696672616d65776f726b2e636f6d2f696d6167652f64657369676e2f6c6f676f2f796969335f66756c6c5f666f725f6c696768742e737667)

Inertia
=======

[](#inertia)

 [ ![PHPUnit](https://camo.githubusercontent.com/65ee72ef5071cd2b9740063b50ff82c42166f96d581d5f3c3fb5600434f47948/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796969322d657874656e73696f6e732f696e65727469612f6275696c642e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d504850556e6974) ](https://github.com/yii2-extensions/inertia/actions/workflows/build.yml) [ ![Mutation Testing](https://camo.githubusercontent.com/d3d912eee3c79e08d98022ca398961ea797d0a6d3880cdd38aa73221810594e1/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666f722d7468652d62616467652675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246796969322d657874656e73696f6e73253246696e65727469612532466d61696e) ](https://dashboard.stryker-mutator.io/reports/github.com/yii2-extensions/inertia/main) [ ![PHPStan](https://camo.githubusercontent.com/4c090fb58e18b692323d980cbaf0154e5e8310bf98da515698b608239f4465bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796969322d657874656e73696f6e732f696e65727469612f7374617469632e796d6c3f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6162656c3d5048505374616e) ](https://github.com/yii2-extensions/inertia/actions/workflows/static.yml)

 **Inertia.js server-side integration layer for [Yii2](https://github.com/yiisoft/yii2/tree/22.0)**
 *Server-driven pages, shared props, redirects, and asset version handling without jQuery*

Features
--------

[](#features)

  ![Feature Overview](./docs/svgs/features.svg)Overview
--------

[](#overview)

`yii2-extensions/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-extensions/inertia-vue`, `yii2-extensions/inertia-react`, and `yii2-extensions/inertia-svelte` can reuse.

Installation
------------

[](#installation)

```
composer require yii2-extensions/inertia:^0.1
```

Register the bootstrap class in your application configuration:

```
return [
    'bootstrap' => [\yii\inertia\Bootstrap::class],
];
```

Quick start
-----------

[](#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],
            ]
        );
    }
}
```

Or inject the renderer contract. `Bootstrap` binds `ResponseRendererInterface` to `InertiaRenderer` in the DI container, so the action stays decoupled from the Inertia implementation and overlays (Inertia, JSON, API) can swap the renderer without rewriting controller code:

```
use yii\inertia\web\ResponseRendererInterface;
use yii\web\{Controller, Response};

final class SiteController extends Controller
{
    public function __construct(
        $id,
        $module,
        private readonly ResponseRendererInterface $renderer,
        $config = [],
    ) {
        parent::__construct($id, $module, $config);
    }

    public function actionIndex(): Response|string
    {
        return $this->renderer->render('Dashboard', ['stats' => ['visits' => 42]]);
    }
}
```

Configuration example
---------------------

[](#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],
        ],
    ],
];
```

Dev server support (Vite)
-------------------------

[](#dev-server-support-vite)

The bundled `\yii\inertia\Vite` helper component renders asset tags for both development and production. When `devMode`is `true`, it emits `@vite/client` plus each configured entrypoint from `devServerUrl`, enabling Vite's HMR WebSocket end-to-end. When `devMode` is `false`, it reads the manifest at `manifestPath` and renders hashed asset tags for production.

Typical development flow: run `npm run dev` to start the Vite dev server and launch Yii2 with a dev environment flag (for example, `YII_ENV=dev ./yii serve`). `YII_ENV` does not toggle `Vite::$devMode` on its own; your application configuration must wire the two together, for example:

```
'components' => [
    'inertiaVite' => [
        'class' => \yii\inertia\Vite::class,
        'devMode' => YII_ENV === 'dev',
        // ...
    ],
],
```

For framework-specific setup, see:

- [`yii2-extensions/inertia-react`](https://github.com/yii2-extensions/inertia-react) — React Refresh preamble auto-injection.
- [`yii2-extensions/inertia-vue`](https://github.com/yii2-extensions/inertia-vue) — Vue HMR (no extra preamble).

Prop types (v3)
---------------

[](#prop-types-v3)

The package supports the Inertia v3 prop types for fine-grained control over when and how props are resolved:

```
use yii\inertia\Inertia;

return Inertia::render(
    'Dashboard',
    [
        'stats' => $stats,                                              // regular prop
        'users' => Inertia::defer(fn () => User::find()->all()),        // loaded after render
        'activity' => Inertia::optional(fn () => $user->getActivity()), // only on partial reload
        'auth' => Inertia::always(fn () => ['user' => $identity]),      // always included
        'items' => Inertia::merge($paginated)->append('data', 'id'),    // merge instead of replace
        'countries' => Inertia::once(fn () => Country::find()->all()),  // resolved once, cached
    ],
);
```

See the [Usage Examples](docs/examples.md) for detailed documentation on each prop type.

Validation and flash messages
-----------------------------

[](#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]);
```

CSRF protection
---------------

[](#csrf-protection)

Drop in `yii\inertia\web\Request` to enable Inertia's automatic cookie-to-header CSRF flow:

```
'request' => [
    'class' => \yii\inertia\web\Request::class,
    'cookieValidationKey' => 'your-secret-key',
],
```

Inertia's HTTP client reads the `XSRF-TOKEN` cookie and sends it as `X-XSRF-TOKEN` automatically no client-side configuration required. See the [Configuration Reference](docs/configuration.md) for details.

Package boundaries
------------------

[](#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
-------------

[](#documentation)

For detailed configuration options and advanced usage.

- 📚 [Installation Guide](docs/installation.md)
- ⚙️ [Configuration Reference](docs/configuration.md)
- 💡 [Usage Examples](docs/examples.md)
- 🧪 [Testing Guide](docs/testing.md)

Package information
-------------------

[](#package-information)

[![PHP](https://camo.githubusercontent.com/f04357fef9ebcd99ed76d5414552bcd1ce849df0ee1d4faf8e991f54c966d508/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f253345253344382e332d3737374242342e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://www.php.net/releases/8.3/en.php)[![Yii 22.0.x](https://camo.githubusercontent.com/6419cb138fb08a8fcb971e8e780bed42fdb74f683a39b22ca0cd2059f246ce43/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f32322e302e782d3030373341412e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d796969266c6f676f436f6c6f723d7768697465)](https://github.com/yiisoft/yii2/tree/22.0)[![Latest Stable Version](https://camo.githubusercontent.com/837cd5094ca664accd66633be315aba764ea66115e9b8634fa4ebf4068115cc8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796969322d657874656e73696f6e732f696e65727469612e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d7768697465266c6162656c3d537461626c65)](https://packagist.org/packages/yii2-extensions/inertia)[![Total Downloads](https://camo.githubusercontent.com/30f6bbb9ecf0f375f4b99c8099f72bff2e954b51a0d10252f0314cf7dea0e322/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796969322d657874656e73696f6e732f696e65727469612e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d636f6d706f736572266c6f676f436f6c6f723d7768697465266c6162656c3d446f776e6c6f616473)](https://packagist.org/packages/yii2-extensions/inertia)

Quality code
------------

[](#quality-code)

[![Codecov](https://camo.githubusercontent.com/fa37d959e6719d2fe8dbd066d94db08aee9545891ee4bd7a54f6d48312d7f823/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f796969322d657874656e73696f6e732f696e65727469612e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d636f6465636f76266c6f676f436f6c6f723d7768697465266c6162656c3d436f766572616765)](https://codecov.io/github/yii2-extensions/inertia)[![PHPStan Level Max](https://camo.githubusercontent.com/b1aeb44257ce46737d1787123b534aab9dded28219f828e4ae13a1e3b460f53c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532304d61782d3446354439352e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465)](https://github.com/yii2-extensions/inertia/actions/workflows/static.yml)[![Super-Linter](https://camo.githubusercontent.com/d0aa0a9403da054cf0103e3014753257974f903a312b2c36fe483e274bbbf6ec/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f796969322d657874656e73696f6e732f696e65727469612f6c696e7465722e796d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d53757065722d4c696e746572266c6f676f3d676974687562)](https://github.com/yii2-extensions/inertia/actions/workflows/linter.yml)[![StyleCI](https://camo.githubusercontent.com/2e44ba381d6c9ab95b548566772bd17337dc56f8a6a646974bf7277720e5be9d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5374796c6543492d5061737365642d3434434331312e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562266c6f676f436f6c6f723d7768697465)](https://github.styleci.io/repos/1196150046?branch=main)

License
-------

[](#license)

[![License](https://camo.githubusercontent.com/680c8d62ba2d5a71d7099b6e81114fb0b22d99086c121fd178e1149afc669d44/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442d2d332d2d436c617573652d627269676874677265656e2e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d6f70656e736f75726365696e6974696174697665266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)](LICENSE)

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance92

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/524d2b46690f41fce7188d369488a35e7624e6c5a264d82aacd08548bfd156ab?d=identicon)[terabytesoftw](/maintainers/terabytesoftw)

---

Top Contributors

[![terabytesoftw](https://avatars.githubusercontent.com/u/42547589?v=4)](https://github.com/terabytesoftw "terabytesoftw (23 commits)")

---

Tags

inertiainertiajsphpserver-driven-uiserver-side-renderingsingle-page-applicationsspayii2phpinertiayii2SPAserver-driven

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/yii2-extensions-inertia/health.svg)

```
[![Health](https://phpackages.com/badges/yii2-extensions-inertia/health.svg)](https://phpackages.com/packages/yii2-extensions-inertia)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
