TetherPHP

Routing

An elegant routing solution

TetherPHP's routing system is designed to be simple and intuitive, allowing you to define routes with minimal effort.

Routes are defined in the routes/web.php file, where you can specify the URL patterns and the corresponding actions.

On this page

Defining routes

$router->get('/path', YourAction::class);

In this example, the /path URL will trigger the YourAction class when accessed via a GET request. The action class will then be invoked and trigger your domain logic and return a responder.

For POST requests, you can define routes similarly:

$router->post('/path', YourAction::class);

Returning Views

TetherPHP is an ADR framework, meaning by design, when calling a route an Action is invoked, Domain business logic is executed, and a Responder is returned.

This can become overkill when you need to return some static HTML, CSS and JavaScript.

To keep the code base cleaner, you can return views directly when making a GET request:

$router->view('/path', 'pages.home');

Dynamic Routes

Dynamic routes can be defined using placeholders in the URL. For example:

$router->get('/user/{id}', UserAction::class);