The future of symfony routing

If you follow the symfony timeline, you probably saw quite a few changesets dedicated to the routing functionality lately. Fabien has been refactoring the routing to make it a normal object - not a singleton - in the trunk; and I have been working on expanding the route syntax in the routing branch.

If you look closely, it means that routing will be more powerful, easier to tweak, and faster.

With the new routing system, routes can use any separator between tokens. For instance, you can have such rules that were not possible before:

permalink:
  url: /:day-:month-:year/:title
  params: { module: content, action: permalink }

multiformat_list:
  url: /articles/list.:format
  params: { module: article, action: list, format: html }

The route syntax was originally a port of the Ruby in Rails routing system. That explains why tokens are prefixed by a colon (:), but that doesn’t really make sense in PHP. That’s why the new routing system now accepts tokens prefixed by a dollar sign ($), which will look more familiar to PHP developers:

permalink:
  url: /$day-$month-$year/$title
  params: { module: content, action: permalink }

multiformat_list:
  url: /articles/list.$format
  params: { module: article, action: list, format: html }

A new default rule was added to the routing.yml, and together with a hook in the controller, it allows for built-in support of PJS templates. That’s right, the ability to include dynamically generated JavaScript files, available in symfony 1.0 with sfPJSPlugin, will be a native functionality of symfony 1.1. This implementation allows for caching of generated JavaScript files with the regular caching system.

<?php echo pjs_include_tag('foo/bar?id=12') ?>
// will generate in HTML
<script language="JavaScript" type="text/javascript" src="/js/foo/bar/id/12.pjs"></script>

There is more to come, but the limits are already pushed much further than where they used to be.

10 Comments so far

  1. halk on July 4th, 2007

    These are very good news. More flexible and legible.

  2. Son on July 4th, 2007

    Nice! Can’t wait for 1.1 to be released.

    By the way, just wondering when is 1.1 scheduled to be released?

  3. Piers on July 5th, 2007

    Fantastic news. Better support for various tokens is definitely something i will be putting to use very quickly.

    Does the change in token preffix mean current routing files will need to be updated to $?

  4. François Zaninotto on July 6th, 2007

    @Piers: No, the change is entirely backward-compatible; the routing system will accept boths tokens prefixed with : and $.

    @Son: We’re scheduling it for the end of the summer, we’ll see if we can make it. There’s a lot in the todo-list…

  5. Markus on July 9th, 2007

    Is the todo-list for 1.1 online so we can have a look at it?

  6. Son on July 10th, 2007

    Markus, I think it might be here, but I’m sure this is no way the comprehensive list.

    http://trac.symfony-project.com/trac/roadmap

    Question for Francois: Are you guys planning on incorporating the latest version of Propel into 1.1?

  7. François Zaninotto on July 10th, 2007

    The to-do list is constituted for one half of the tickets we want to fix for the 1.1, and for the other half of a list of structural changes that Fabien has in mind and that have already started (desingletonization, better i18n, better view logic, and a lot more to come).

    As for Propel 1.3, it might be a matter of schedule. It is actually in Beta, and the development is not going very fast (as compared, for instance, to Doctrine). If we want it integrated into sf 1.1, we’ll need a stable version early enough so that we can test it and rewrite part of the documentation for it. So, for the moment, the decision is not yet made.

  8. Son on July 10th, 2007

    Sounds good. Quick question though, Doctrine is said to be supported from the 1.1 Roadmap. Is that full integration like the way Propel is in 1.0.x? I’m starting a new project and I’m just trying to figure out between the two ORMs, which to focus on the most.

    By the way, thanks for all your replies and great work on the framework! I’m looking forward to 1.1.

  9. François Zaninotto on July 10th, 2007

    Son: As Doctrine dropped PHP 5.1 support, it can’t be the default ORM for symfony 1.1. Furthermore, it has been experiencing a lot of changes lately and is not stable enough for symfony, not yet.

    We keep a close eye on the progress of Doctrine and look forward to integrating it the way Propel is. The sfDoctrine plugin does that pretty well. But the 1.1 will come too soon for Doctrine, I suppose.

  10. Son on July 16th, 2007

    I see. No problems. :) Thanks!

Leave a reply