PHPackages                             ride/lib-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ride/lib-router

ActiveLibrary[Framework](/categories/framework)

ride/lib-router
===============

Router library of the Ride framework

1.4.1(8y ago)26.0k1[1 PRs](https://github.com/all-ride/ride-lib-router/pulls)10MITPHP

Since Sep 21Pushed 8y ago8 watchersCompare

[ Source](https://github.com/all-ride/ride-lib-router)[ Packagist](https://packagist.org/packages/ride/lib-router)[ RSS](/packages/ride-lib-router/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (31)Used By (10)

Ride: Router Library
====================

[](#ride-router-library)

Router library of the PHP Ride framework.

Routing is used to translate a incoming HTTP request to a callback.

What's In This Library
----------------------

[](#whats-in-this-library)

### Route

[](#route)

A *Route* defines a request path with the callback.

The definition of a route provides 2 ways for passing arguments to the action:

- A placeholder in the path with the name of the variable for a dynamic value. The name of the variable should be between %.
- A static value in the definition

You can optionally set an id to a route to make retrieval easy in your code. By using ids, you are able to override a path through your configuration without changing your code.

Keep your code clean by implementing only one action in a callback. Limiting a route to a specific, or multiple request methods (GET, POST, ...) can help you with this.

You can set a base URL to a route to limit your action to a certain domain.

A locale can also be set to a route. This is usable to act on localized paths later on the process.

You can help your security layer by adding permissions to your route. The router itself will not take these into account.

### Alias

[](#alias)

An *Alias* defines an aliased path for existing paths with query parameters.

It can be forced in order to redirect the original path to the alias.

### RouteContainer

[](#routecontainer)

A *RouteContainer* is the collection of your routes. It offers an easy interface to manage the routes and aliases.

Use the route container to generate an URL in order for the aliases to be handled.

### Router

[](#router)

The *Router* is what performes the actual translating of the incoming request to the route. It's a simple interface but a generic implementation is added to the library.

### RouterResult

[](#routerresult)

The result of a route action on the router is a *RouterResult* object.

This object has 3 possible states:

- **empty**: no route matched the incoming request
- **allowed methods are set**: a route matched but not for the incoming request method
- **alias is set**: a forced alias is matched and the request should be redirected
- **route is set**: a route matched and the callback should be invoked

### Url

[](#url)

An *Url* is a mutable object to update and manipulate a generated URL.

Code Sample
-----------

[](#code-sample)

Check this code sample to see the possibilities of this library:

```
