Search

A new extension, "Versatile Router" is now available for download. Comments and feedback can be left here but if you discover any issues, please post it on the issue tracker.

Another routing extension. I wrote this one so that I could do things that the other two routing extensions don't allow.

As an example, here is an AJAX routing group which uses Versatile Router's ability to access the values in $_SERVER and $_REQUEST:

<?php namespace versatile_router;

group(
    when_match('CONTENT_TYPE', '/^application/x-www-form-urlencoded/'),
    function(){
        get('/article/:title/', '/article-ajax-page/{:title}/', when_is('article-page')); 
        get('/article/:title/', '/article-ajax-comments/{:title}/', when_is('comments-page')); 
        post('/article/:title/', '/article-ajax-comments/{:title}/');
    }
);

Update, 20th March 2014

For version 0.2, the above has to be rewritten:

<?php namespace versatile_router;

group(
    function(){
        get('/article/:title/', '/article-ajax-page/{:title}/', array(when_true.'article-page')); 
        get('/article/:title/', '/article-ajax-comments/{:title}/', array(when_true.'comments-page')); 
        post('/article/:title/', '/article-ajax-comments/{:title}/');
    },
    array(when_match.'CONTENT_TYPE /^application/x-www-form-urlencoded/')
);

Versatile Router updated to version 0.2 on 20th of March 2014

Changes have been made to the routing syntax. See the read-me file.

Version 0.2 allows URL parameters to be added Symphony's parameter pool. If you use this feature then there is no need to specify URL parameters in the page definition.

Thus something like this can be done:

get('/articles/:pagenum/', '/aricles-page/[:pagenum], array(when_number.':pagenum'));
get('/articles/:category/:pagenum/', '/articles-page/[:category :pagenum]', array(when_number.':pagenum'));
get('/articles/:category/', '/articles-page/[:category]');

At present, a parameter name cannot contain a hyphen. Pardon that shortcomming.

Hi Peter. Sorry for the noob question but can I use this to parse any URL? For example, with the default symphony structure, to simplify from:

articles/entry/article-title

to:

articles/article-title

Currently I'm using a very bulky xsl:if/when scenario which is slow as it loads the whole section. Think this is what I need as it handles conditions too?

Thanks!

Like this:

get('/articles/entry/:title/', '/articles/{:title}/');

That's great! Can I use it to change/mask a section name? So change articles to something else?

Better yet... Would it be possible for me to take a category and use that as the section name?

So rather than /articles/category/article-title just display: /category/article-title

?? Is that what this is effectively doing?

 get('/articles/:category/', '/articles-page/[:category]');

Since a route corresponds to a page rather than a section, it is better not to muddle the two. It is only the destinastion route that needs to correspond to a real page, so either

(a) get('/pseudo-page/:parameter/', '/real-page/{:parameter}/');

or (b) get('/pseudo-page/:parameter/', '/real-page/[:parameter]');

can be done. The difference between (a) and (b) is that with (b) there is no need to specify any URL parameters in your page blueprint, since Versatile Router will add the names in square brackets to the parameter table.

If you want to you can have

get('/:category/:title/', '/article/{:category}/{:title}/');

or get(/':category/:title/', '/article/[:category :title]');.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details