october/router

This package is abandoned and no longer maintained. No replacement package was suggested.

Basic URL Router

Maintainers

👁 october

Package info

github.com/octoberrain/router

Homepage

pkg:composer/october/router

Statistics

Installs: 664

Dependents: 0

Suggesters: 0

Stars: 2

v1.0.419 2016-11-27 17:36 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d68651423e421499d6521ec501575947631c5cf8

  • Alexey Bobkov <aleksey.bobkov.woop@gmail.com>
  • Samuel Georges <daftspunky.woop@gmail.com>

urlrouterSimpleurioctoberoctober cms

This package is not auto-updated.

Last update: 2018-12-08 08:20:53 UTC


README

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: array(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', array('id' => 2));