Routing

Route registration

All routes are written in the routes/Routes.php file.

This example initializes the Home route with the Home controller, Index action and GET method.

$Route->Add()
    ->get('/home')
    ->controller(HomeController::class)
    ->action('IndexAction');

You can also write routes in the same file using arrays.

In this similar example, the home route is initialized using the Home controller, Index action, and GET method.

[
    "URI" => '/home',
    "Method" => 'GET',
    "Controller" => "App\Controllers\HomeController",
    "Action" => "IndexAction"
]

Parameters

If you want to use certain parameters in your route so that you can use them in your application, you can specify them in the route.

$Route->Add()
    ->get('/users/{id}')
    ->controller(HomeController::class)
    ->action('IndexAction');

To get the options in the application, use the following method.

$id = Request::route('id');

Available Router Methods

Below is a list of all supported routing methods.

Route->Add()->get('/home')
Route->Add()->post('/home')
Route->Add()->put('/home')
Route->Add()->patch('/home')
Route->Add()->delete('/home')