Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Named regex routes
  • Hey folks, is there a way to have named route parameters that match certain regular expressions? Just like
    return array(
        'blog/:year/:month/:id' => 'blog/entry', // Routes /blog/2010/11/entry_name to /blog/entry
    );
    
    combined with
    return array(
        'blog/(:any)'      => 'blog/entry/$1', // Routes /blog/entry_name to /blog/entry/entry_name
        '(:segment)/about' => 'site/about/$1', // Routes /en/about to /site/about/en
        '(\d{2})/about'    => 'site/about/$1', // Routes /12/about to /site/about/12
    );
    

    (both code snippets were taken from docs) Thanks in advance!
  • To me it's not exactly clear what you mean. Named routes are routes that have a unique name, so you can refer to them in your code when you generate anchors (as opposed to hardcode the URI of the anchor). Router::get(), which is used to retrieve a named route in your code, supports the first syntax, for which you have to pass a parameter array as second argument. As documented it doesn't support regex routes (like the last one in your second snippet). Problem with that is you don't know what to replace it with to make it a proper URI. If you have a suggestion, I'm all ears...

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion