maskulabs/inertia-yii
最新稳定版本:1.0.0
Composer 安装命令:
composer require maskulabs/inertia-yii
包简介
Yii3 integration for Inertia.js v3 with server-side rendering support, middleware, validation error handling, session and flash adapters, and Vite asset integration.
README 文档
README
Yii integration for maskulabs/inertia-psr.
inertia-yii provides the Yii-specific pieces needed to use Inertia.js v3 in Yii applications, including rendering, middleware, validation error handling, session / flash adapters, and Vite integration.
Official Inertia.js documentation:
Features
- Yii-specific
Inertiaimplementation - HTML and JSON Inertia responses
- Shared props middleware
- Validation exception middleware with flashed errors
- Yii session and flash adapters
- Yii response and stream factories
- Vite dev server and manifest integration
Requirements
- PHP 8.5+
maskulabs/inertia-psr- Yii packages required by
composer.json
Installation
Install the package with Composer:
composer require maskulabs/inertia-yii
Looking for a ready application template?
If you want a ready starting point instead of wiring everything manually, see maskulabs/inertia-app.
It is an application template based on yiisoft/app with Inertia.js integration already configured.
Quick start
<?php use MaskuLabs\InertiaPsr\InertiaInterface; use MaskuLabs\InertiaPsr\Response\ResponseInterface; final readonly class DashboardAction { public function __construct( private InertiaInterface $inertia, ) {} public function __invoke(): ResponseInterface { return $this->inertia->render('Dashboard', [ 'stats' => [ 'users' => 120, 'sales' => 54, ], ]); } }
Root view
The package ships with a default root view, but you can also configure your own.
Your root view should:
- render the serialized Inertia page data
- provide the frontend mount element
- include your frontend JavaScript and CSS assets
Shared props
ShareMiddleware is intended to be configured in the Yii middleware stack.
Example:
<?php use MaskuLabs\InertiaPsr\Middleware\InertiaMiddleware; use MaskuLabs\InertiaYii\Middleware\ShareMiddleware as InertiaShareMiddleware; return [ InertiaMiddleware::class, [ 'class' => InertiaShareMiddleware::class, 'withDefinitions()' => [ Reference::to(I18n::class), Reference::to(Layout::class), ], ], ];
Validation errors
ValidationExceptionMiddleware catches validation exceptions and flashes formatted errors so they can be returned to the frontend after redirect.
Example:
<?php use MaskuLabs\InertiaYii\Exception\ValidationException; if (!$formHydrator->populateFromPostAndValidate($loginForm, $request)) { throw new ValidationException($loginForm->getValidationResult()); }
Vite integration
ViteAsset supports two common modes:
- development mode using the Vite dev server
- production mode using
.vite/manifest.json
License
MIT
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17