Total Pageviews

Thursday 29 May 2014

routemap :Routes for PHP

RouteMap is an implementation of Rails like routes system for mapping URLs to controllers/actions and generating URLs. Useful even for code which doesn't use MVC pattern. This particular implementation is inspired by Pylons' Routes2 system adapted to PHP5.
Basically, you map an URL to some method. e.g.
http://example.net/index.php?archive/2008/01/01 or
http://example.net/archive/2008/01/01 (with URL rewriting)
could map to a single method call
News::show("2008", "01", "01");
where "route" is represented by 'archive/:year/:month/:day' and year, month, and day denote "route arguments". For each route, you decide which action should be executed. See Manual for more detailed introduction to URL routing with RouteMap.
An unintended consequence of this routing stuff is that your URLs are now pretty, cool and RESTful.

News

May 15th, 2008 - Version 0.9.1 - License change, RouteMap is now licensed under the terms of New BSD license.
May 7th, 2008 - Version 0.9.0 released with important improvements for route matching
  • New matching order: static, dynamic and wild-card routes
  • Always prefer routes with static parts against the ones with arguments.
April 16th, 2008 - Bugfix: Don't exit too early during wild-card route "accelerated" match. (in source code repository)
April 10th, 2008 - Some minor fixes are in source code repository. 1.0 will be released after we finish developer documentation (in a week or two). Unitil then, read the source.

Features

  • named routes (dynamic, static and passive)
  • route matching
  • route argument requirements (filtered with PCRE)
  • URL generation
  • simple dispatching (optional)
Above all, we value simple, explicit code, so:
  • All routes are explicit, route minimization is not supported (and probably never will be)
  • Controller and action are not embedded in route itself, but explicit arguments to RouteMap::connect()
  • We don't use regular expressions for route matching, they are used only when checking requirements for route arguments.

Notes

Many PHP MVC frameworks have some kind of Routes implementation (Zend, Code Igniter, CakePHP, Symfony), for various reasons I find them inadequate, ugly, or just too big ...
There is also another Pylons' Routes port from Horde project: http://dev.horde.org/routes. I warmly recommend it if, for some strange reason, you don't want to use RouteMap. They even have route minimization and other clever features.
First release of RouteMap was written from scratch in just two days. It is only one file/class, around 500 lines of code. It was fun to write, and hopefuly fun to use。

from http://code.google.com/p/routemap/