Skip to content

Simple PHP Router class (supports REST and reverse routing)

License

Notifications You must be signed in to change notification settings

matzhouse/PHP-Router

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Router class

A simple Rails inspired PHP router class.

  • Usage of different HTTP Methods
  • REST / Resourceful routing
  • Reversed routing using named routes
  • Dynamic URL's: use URL segments as parameters.

Usage

<?php
require 'Router.php';
require 'Route.php';

$router = new Router();

$router->setBasePath('/PHP-Router');

// defining routes can be as simple as this
$router->map('/', 'users#index');

// or somewhat more complicated
$router->map('/users/:id/edit/', array('controller' => 'SomeController', 'action' => 'someAction'), array('methods' => 'GET,PUT', 'name' => 'users_edit'));

// You can even specify closures as the Route's target
$router->map('/hello/:name', function($name) { echo "Hello $name."; });

// match current request URL & http method
$target = $router->matchCurrentRequest();
var_dump($target);

// generate an URL 
$router->generate('users_edit', array('id' => 5));

More information

Have a look at the example.php file or read trough the class' documentation for a better understanding on how to use this class.

License

MIT Licensed, http://www.opensource.org/licenses/MIT

About

Simple PHP Router class (supports REST and reverse routing)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published