3 A simple Rails inspired PHP router class.
5 * Usage of different HTTP Methods
6 * REST / Resourceful routing
7 * Reversed routing using named routes
8 * Dynamic URL's: use URL segments as parameters.
12 - [Danny van Kooten](https://github.com/dannyvankooten)
13 - [Jefersson Nathan](https://github.com/malukenho)
15 # Easy to install with **composer**
20 "dannyvankooten/php-router": "dev-master"
29 Create a simple .htaccess file on your root directory.
32 Options +FollowSymLinks
34 RewriteRule ^(.*)$ index.php [NC,L]
37 It's a simple example of routers in action
41 require __DIR__.'/vendor/autoload.php';
43 use PHPRouter\RouteCollection;
47 $collection = new RouteCollection();
48 $collection->attachRoute(new Route('/users/', array(
49 '_controller' => 'someController::users_create',
53 $collection->attachRoute(new Route('/', array(
54 '_controller' => 'someController::indexAction',
58 $router = new Router($collection);
59 $router->setBasePath('/PHP-Router');
60 $route = $router->matchCurrentRequest();
65 ## Load routers from a `yaml` file
67 We can define in a `yaml` file all the routes of our application. This facilitates our life when we need to *migrate*, *modify*, or later *add* new routes.
69 The route definition should follow the example below:
75 index: [/index, someClass.indexAction, GET]
76 contact: [/contact, someClass.contactAction, GET]
77 about: [/about, someClass.aboutAction, GET]
79 In our **Front Controller** would have something like:
83 require __DIR__.'/vendor/autoload.php';
85 use PHPRouter\RouteCollection;
90 $config = Config::loadFromFile(__DIR__.'/router.yaml');
91 $router = Router::parseConfig($config);
92 $router->matchCurrentRequest();
96 Have a look at the example.php file or read trough the class' documentation for a better understanding on how to use this class.
98 If you like PHP Router you might also like [AltoRouter](//github.com/dannyvankooten/AltoRouter).
101 MIT Licensed, http://www.opensource.org/licenses/MIT