PHPackages                             openclerk/routing - 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. openclerk/routing

ActiveLibrary[Framework](/categories/framework)

openclerk/routing
=================

A library for simple routing in PHP

0.1.0(8y ago)01753PHP

Since Sep 11Pushed 8y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (2)Used By (0)

openclerk/routing [![Build Status](https://camo.githubusercontent.com/d67b0f6e258f08a169ec03db410d5a000f35987fc28aad5409db21fc9869ac94/68747470733a2f2f7472617669732d63692e6f72672f6f70656e636c65726b2f726f7574696e672e737667)](https://travis-ci.org/openclerk/routing)
========================================================================================================================================================================================================================================================================

[](#openclerkrouting-)

A library for simple routing in PHP.

Using
-----

[](#using)

This project uses [openclerk/config](https://github.com/openclerk/config) for config management.

First configure the component with site-specific values:

```
Openclerk\Config::merge(array(
  "absolute_url" => "http://localhost/path/",
));
```

Add a simple router file:

```

```

Add a `.htaccess` that translates paths to this router:

```
RewriteEngine on

# Forbid access to any child PHP scripts
RewriteRule ^([^\.]+)/([^\.]+).php$   -                   [F]

RewriteRule ^([^\.]+)$                router.php?path=$1  [L,QSA]

```

Define site routes:

```
// set up routes
\Openclerk\Router::addRoutes(array(
  "security/login/password" => "security/login.php?type=password",
  "security/login/:key" => "security/login-:key.php?type=:key",
  // by default any unmatched routes will require .php
));
```

Now you can use `url_for()` and `absolute_url_for()`:

```
