yiiex/inertiajs

Inertia.js server adapter

Maintainers

Package info

github.com/yiiex/inertiajs

pkg:composer/yiiex/inertiajs

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-05-24 14:55 UTC

This package is auto-updated.

Last update: 2026-06-24 15:48:04 UTC


README

Simple Inertia.js server adapter for Yii3 framework.

Installation

composer require yiiex/inertiajs

Current Limitations

  • Server-side rendering (SSR) is not supported
  • Asset versioning is not implemented
  • Only JSON responses for Inertia requests, no partial reloads

Planned Features

  • SSR support
  • Asset versioning
  • Partial reloads

Setup

1. Add middleware

Application::class => [
    '__construct()' => [
        'dispatcher' => DynamicReference::to([
            'class' => MiddlewareDispatcher::class,
            'withMiddlewares()' => [
                [
                    // Your other middlewares
                    InertiaMiddleware::class,
                    Router::class,
                ],
            ],
        ]),
        'fallbackHandler' => Reference::to(NotFoundHandler::class),
    ],
],

2. Create root view

<?php

declare(strict_types=1);

/**
 * @var Yiisoft\View\WebView $this
 * @var string $content
 * @var \Yiiex\Inertia\Inertia $inertia
 */

$this->beginPage()
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title inertia><?= $this->getTitle() ?></title>
    <?php $this->head() ?>
</head>
<body>
    <?php $this->beginBody() ?>
    <?= $content ?>
    <?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

3. Create Inertia page component

<?php

/**
 * @var \Yiiex\Inertia\Inertia $inertia
 */
?>
<div id="app"
     data-page="<?= htmlspecialchars($inertia->dataPage(), ENT_QUOTES, 'UTF-8', true) ?>"
></div>

Usage

use Yiiex\Inertia\Inertia;

class UserController
{
    public function index(Inertia $inertia, UserRepository $repository)
    {
        return $inertia->render('Users/Index', [
            'users' => $repository->findAll(),
        ]);
    }
}

Sharing Props

class CustomInertiaMiddleware extends \Yiiex\Inertia\InertiaMiddleware
{
    protected function beforeAction(): void
    {
        $this->inertia->share([
            'auth' => ['user' => $user],
            'php' => PHP_VERSION,
        ]);
    }
}

Lazy Props

return $inertia->render('Dashboard', [
    'stats' => fn() => HeavyQuery::getStats(),
]);

License

MIT