PHP code example of trianayulianto / inertia-codeigniter-4

1. Go to this page and download the library: Download trianayulianto/inertia-codeigniter-4 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/ */

    

trianayulianto / inertia-codeigniter-4 example snippets


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title inertia>CI4-Inertia</title>

    <!-- ViteJs Helper -->
    <?= vite_react_refresh() 



namespace App\Filters;

use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\Request;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware implements FilterInterface
{
    /**
     * The root template that is loaded on the first page visit.
     *
     * @var string
     */
    protected $rootView = 'app';

    /**
     * Determine the current asset version.
     *
     * @param  \CodeIgniter\HTTP\Request  $request
     * @return string|null
     */
    public function version(Request $request)
    {
        return parent::version($request);
    }

    /**
     * Define the props that are shared by default.
     *
     * @param  \CodeIgniter\HTTP\Request  $request
     * @return array
     */
    public function share(Request $request)
    {
        return array_merge(parent::share($request), []);
    }
}

use Inertia\Inertia;

class EventsController extends Controller
{
    public function show($id)
    {
        $event = Event::find($id);

        return Inertia::render('Event/Show', [
            'event' => $event,
        ]);
    }
}