1. Go to this page and download the library: Download tebe/yii2-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/ */
namespace app\components;
use yii\base\ActionFilter;
class SharedDataFilter extends ActionFilter
{
public function beforeAction()
{
$shared = [
'user' => $this->getUser(),
'flash' => $this->getFlashMessages(),
'errors' => $this->getFormErrors()
];
Yii::$app->get('inertia')->share($shared);
return parent::beforeAction($action);
}
}
namespace app\controllers;
use app\components\SharedDataFilter;
use tebe\inertia\web\Controller;
class ContactController extends Controller
{
public function behaviors()
{
return [
[
'class' => SharedDataFilter::class
]
];
}
public function actionIndex()
{
// your action code
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.