1. Go to this page and download the library: Download yii2-extensions/inertia library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
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]],
);
}
}
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],
]
);
}
}
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]]);
}
}