chriso/klein.php — pull request #113 by Rican7 (2013-07-03 04:13:57+00:00)
Title: Feature - Reverse Routing

After intense interest was made by @gbouthenot, @unstoppablecarl, @sammyshp, and after seeing other routing libraries implement similar functionality, and finally after seeing @gbouthenot implement this functionality in a fork of the origin Klein 1.0 codebase, I've created a new feature for **"reverse routing"**.

This feature allows you to name routes when defining them, so you can later refer to them in other areas of the code and get the "path" for a route with the variable params filled/replaced like a parsed template.

Please, let me know what all involved think of the feature's design. Oh, and @gbouthenot, I [attributed you in the comments](https://github.com/Rican7/klein.php/blob/5cd05aa6a4a9e1aec33b2f6d60d48d7c5b957f2c/src/Klein/Klein.php#L673)

Here's an example:

```php
// Define AND name our route
$klein->respond(
'/dogs/[i:dog_id]/collars/[a:collar_slug]/?',
function () {
}
)->setName('dog-collar-details'); // Name it whatever you want

/**
* And then somewhere later in your code....
*/

// Echo's "/dogs/[i:dog_id]/collars/[a:collar_slug]/?"
echo $klein->getPathFor('dog-collar-details');

// Echo's "/dogs/2890/collars/d12f3d1f2d3/?"
echo $klein->getPathFor(
'dog-collar-details',
array(
'dog_id' => 2890,
'collar_slug' => 'd12f3d1f2d3',
)
);
```