Horde/Routes 0.4 Released

  • Posted by Mike Naberezny in PHP

    Horde/Routes 0.4 has been released. Horde/Routes is a URL mapping system for PHP 5 that provides classes for mapping URLs to the controllers and actions of an MVC system. Learn more at the project website or this presentation.

    This version includes a new utility class, Horde_Routes_Printer, a debugging aid that can print out a summary of all routes that are connected to a mapper. It is available through a convenience method from Horde_Routes_Utils:

    $map = new Horde_Routes_Mapper();
    $map->connect('post', ':title',
    $map->connect('feeds', 'feeds/:format',

    This will cause the following information to be printed to php://output:

     post  /:title                  {:controller=>"posts", :action=>"show"}
    feeds  /feeds/:format           {:controller=>"feeds", :action=>"index"}

    You’ll see above that the name of the route (if any) is shown, the route path, and the default values for the route. If a route only matches for a certain HTTP method, this will be shown as well. It’s handy when you have a large number of routes, or resource routes.

    If you’d like the debug output to go somewhere else, pass a stream resource as the first argument to printRoutes(). The output is formatted similarly to the rake routes command from Rails. Although the notation is a little unusual for PHP, it’s compact and readable. See Horde_Routes_Printer if you’d like to modify the format.

    Since it’s release, we’re received a good amount of positive feedback on Horde/Routes. It is now being shared by the upcoming Horde 4 (Rampage), the Seagull framework, and a few others. Check out the integration guide for how to add it to your project.