Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Regex in Named parameters Routes?
  • Hi All;

    Is possible to aply regex to a named  parameter in a route? I have a name parameter for lang( /es, /en, etc...) and i want to force to only get the param if it has 2 letters(\w{2}), but  I dont see it in docs:

    Thanks
  • Can you be more specific to what you exactly want?

    You want to accept "/en/something" and "/es/something" but not "/de/something"?
  • I want accept "/en/something" and "/es/something" but not "eng/something" or "esp/something".

    And i want that segment be named.

    Actually I have this:

            ':lang/(:any)'    => '$2',
            ':lang'           => 'home/index',

    And i want than "lang" only accept (\w{2}) regexp.

  • HarroHarro
    Accepted Answer
    That is not supported by the route syntax, but as a route is a regex, you can add your own. A route like ":lang" is replaced by "(?P<lang>.+?)", so you need to replace the ".+" with your custom regex.

    You can do a

    Debug::dump(Router::$routes)

    to check what route objects are generated from your routes. Each route object has a "translation" property containing the regex that is used to match the route.
  • Thanks Harro, i'll try it 

    I hope it will be a V2 feature :P
  • It already is. :-)

Howdy, Stranger!

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

In this Discussion