PHPackages                             deesoft/yii2-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. deesoft/yii2-inertia

ActiveYii2-extension

deesoft/yii2-inertia
====================

Yii2 inertia js

316PHP

Since Feb 12Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

Yii2 Inertia Adapter
====================

[](#yii2-inertia-adapter)

This is the Yii 2 server-side adapter for [Inertia](https://inertiajs.com).

With Inertia you are able to build single-page apps using classic server-side routing and controllers, without building an API.

See [client-side setup](https://inertiajs.com/client-side-setup) for client instalation.

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

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist deesoft/yii2-inertia "*"

```

or add

```
"deesoft/yii2-inertia": "*"

```

to the require section of your `composer.json` file.

Initialization
--------------

[](#initialization)

```
# php yii inertia/init

```

Usage
-----

[](#usage)

Once the extension is installed, simply use it in your controller :

```
    public function actionIndex()
    {
        $query = User::find();
        $request = Yii::$app->getRequest();
        $query->andFilterWhere([
            'id' => $request->get('id'),
            'active' => $request->get('active'),
        ]);

        $query->andFilterWhere(['ilike', 'username', $request->get('username')])
            ->andFilterWhere(['ilike', 'email', $request->get('email')])
            ->andFilterWhere(['ilike', 'phone', $request->get('phone')]);

        if ($q = $request->get('q')) {
            $query->andWhere([
                'OR',
                ['ilike', 'username', $q],
                ['ilike', 'email', $q],
                ['ilike', 'phone', $q],
            ]);
        }

        $sortAttrs = [
            'id',
            'username',
            'email',
            'phone',
        ];
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'attributes' => $sortAttrs,
            ]
        ]);
        return Inertia::render('user/index', [
                'data' => $dataProvider
        ]);
    }

    public function actionCreate()
    {
        $model = new User();

        if ($this->request->isPost) {
            if ($model->load($this->request->post(), '') && $model->save()) {
                return $this->redirect(['view', 'id' => $model->id]);
            }
        }

        return Inertia::render('user/create', [
            'model' => $model,
        ]);
    }

// defered prop
        return Inertia::render('user/index', [
                'data' => Inertia::defer(function(){
                    return $dataProvider;
                }),
        ]);
// other prop
        return Inertia::render('user/index', [
                'data' => Inertia::scroll(User::find()->where(['active' => true]))->merge(),
                'warehouses' => Inertia::once(function(){
                    return Warehouse::find()->all();
                }),
                'prop1' => Inertia::optional(fn() => Branch::find()->all()),
                'prop2' => Inertia::merge(fn() => Branch::find()->all())->prepend(),
                'prop3' => function(){
                    return Branch::find()->all();
                }
        ]);
```

Configuration
-------------

[](#configuration)

Add configuration to Application $params config.

```
    'components' => [
        ...
    ],
    'params' => [
        'inertia' => [
            'tag' => 'div', // default div
            'id' => 'app', // default app
            'register_vite_asset' => true, // set false when you want handle your vite asset
            'view_file' => '@app/views/app.php', // default @dee/inertia/views/app.php
            'encrypt_history' => true, // default false
        ],
        'inertia.shared' => [
            'user' => function(){
                if(!Yii::$app->user->isGuest){
                    return ['id' => Yii::$app->user->id];
                }
            }
        ],
    ],
```

Vite Asset Bundle
-----------------

[](#vite-asset-bundle)

If you want to handle vite asset with your own, set `Yii::$app->params['inertia.register_vite_asset']` to `false`. To use `ViteAsset` bundle, ensure in `vite.config.js` value of `build.manifest` is `true`.

```
// vite.config.js

        ...
        build: {
            rollupOptions: {
                input: [
                    'client/app.js',
                ],
            },
            manifest: true,
            outDir: 'client/dist',
        },
```

```
// config/web.php

    'components' => [
        ...
        'assetManager' => [
            'bundles' => [
                \dee\inertia\ViteAsset::class => [
                    'bootstrap' => 'client/app.js', // same as build.rollupOptions.input
                    'sourcePath' => '@client/dist', // same as build.outDir
                ]
            ]
        ]
    ]
```

Create Url
----------

[](#create-url)

Use function `yiiUrl` to generate url from route. It's equivalent with `yii\helpers\Url::to()`.

```
const {yiiUrl} = window;

const url = yiiUrl('product/view', {id: row.id}); // equivalent Url::to(['/product/view', id' => $row->id])
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance59

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a5ba97416867dd2bff6c4e2fcd0e52f8b1f8bb7521dcef6b734636009ce834e?d=identicon)[mdmunir](/maintainers/mdmunir)

---

Top Contributors

[![mdmunir](https://avatars.githubusercontent.com/u/5828252?v=4)](https://github.com/mdmunir "mdmunir (44 commits)")

---

Tags

hacktoberfestinertiajsyii2-extension

### Embed Badge

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

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

PHPackages © 2026

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