PHP code example of akara / ci4_route_generator

1. Go to this page and download the library: Download akara/ci4_route_generator 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/ */

    

akara / ci4_route_generator example snippets


namespace App\Controllers;

use Akara\RouteGenerator\RoutePath;
use CodeIgniter\Controller;

class UserController extends Controller
{
    #[RoutePath('/users', 'get')]
    public function index()
    {
        // Your logic here
    }

    #[RoutePath('/users/{id}', 'get', ['auth'])]
    public function show($id)
    {
        // Your logic here
    }
}

namespace App\Controllers;

use Akara\RouteGenerator\RoutePath;
use App\Filters\SessionFilters;
use CodeIgniter\Controller;

class UserController extends Controller
{
    #[RoutePath('/users', 'GET')]
    public function index()
    {
        // Your logic here
    }

    #[RoutePath('/users/{id}', 'GET', [SessionFilters::class])]
    public function show($id)
    {
        // Your logic here
    }
}



// Auto-generated routes
$routes->get('/users',  [App\Controllers\UserController::class, 'index'], ['filter' => []]);
$routes->get('/users/{id}',  [App\Controllers\UserController::class, 'show'], ['filter' => [auth::class]]);
bash
php spark make:route
bash
namespace Config;

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */