PHPackages                             p810/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. [HTTP &amp; Networking](/categories/http)
4. /
5. p810/router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

p810/router
===========

Respond to any requested URI in your application through a single point of entry.

1.1.2(7y ago)020MITPHP

Since Mar 24Pushed 7y ago1 watchersCompare

[ Source](https://github.com/p810/router)[ Packagist](https://packagist.org/packages/p810/router)[ RSS](/packages/p810-router/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

Router
======

[](#router)

> Respond to any requested URI in your application through a single point of entry.

Installation
------------

[](#installation)

```
composer require p810/router

```

Usage
-----

[](#usage)

A route is any URI that you wish for your application to respond to. Routes must be contained within an instance of `RouteCollection`. The route may be checked against `RouteCollection::match()`, which will either throw an exception (`UnmatchedRouteException`) or call the specified callback.

Note that in order to use this, you must configure your Web server to direct requests to the script where this code is placed (e.g., `.htaccess` for Apache).

### Loading controllers

[](#loading-controllers)

You may set a default namespace from which to load classes by calling `Collection::setControllerNamespace()`. Just tell it which namespace is the base of your controllers.

```
$router->setControllerNamespace('MyApp\\Controllers\\');
```

### Dynamic routes

[](#dynamic-routes)

You may pass arguments into your route by using one of the following tokens.

TokenMatch{int}Any integer (0-9).{word}A word (a-zA-Z 0-9).You may specify that a token is optional by prefixing the closing brace with a question mark, like so: `{token?}`

### Example

[](#example)

```
