TPS_web_october/vendor/october/rain/src/Router
Kerim cfd8e76cf4 Git Commit 2022-09-12 11:02:53 +05:00
..
CoreRouter.php Git Commit 2022-09-12 11:02:53 +05:00
Helper.php Git Commit 2022-09-12 11:02:53 +05:00
Router.php Git Commit 2022-09-12 11:02:53 +05:00
RoutingServiceProvider.php Git Commit 2022-09-12 11:02:53 +05:00
Rule.php Git Commit 2022-09-12 11:02:53 +05:00
UrlGenerator.php Git Commit 2022-09-12 11:02:53 +05:00
helpers.php Git Commit 2022-09-12 11:02:53 +05:00
readme.md Git Commit 2022-09-12 11:02:53 +05:00

readme.md

URL Router

URL route patterns follow an easy to read syntax and use in-place named parameters, so there is no need to use regular expressions in most cases.

Creating a route

You should prepare your route like so:

$router = new Router;

// New route with ID: myRouteId
$router->route('myRouteId', '/post/:id');

// New route with ID: anotherRouteId
$router->route('anotherRouteId', '/profile/:username');

Route matching

Once you have prepared your route you can match it like this:

if ($router->match('/post/2')) {

    // Returns: [id => 2]
    $params = $router->getParameters(); 

    // Returns: myRouteId
    $routeId = $router->matchedRoute(); 
}

Reverse matching

You can also reverse match a route by it's identifier:

// Returns: /post/2
$url = $router->url('myRouteId', ['id' => 2]);