Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Route and lang
  • Hello,

    My site is multilingual in english and french.

    I want to have a url "/events" and "/evenements" to display all events and "/event/slug1" "/evenement/slug1" to display one event.

    And my langswitcher must switch to the correct url in the other lang.

    How can i have route multilang with the same name but not the same slug ?

    ex : this routes doesn't wok because of the duplicate names : 

    'events'             => ['event/index', 'name' => 'event_index'],
    'evenements'          => ['event/index', 'name' => 'event_index'],

    'event/(:slug)'      => ['event/view/$2', 'name' => 'event_view'],
    'evenements/(:slug)'  => ['event/view/$2', 'name' => 'event_view'],


    Thank you
  • Ok, so you've implemented multiple languages by hardcoding the URI segments in the routes.
    That indeed doesn't work that way, as the route name must be unique.

    Since routes are parsed using a regex, perhaps this works?

    '(?:events|eventements)'       => ['event/index', 'name' => 'event_index'],
    '(?:events|eventements)/:slug' => ['event/view/$1', 'name' => 'event_view'],

    Since you are using named variables here (slug), which is already a match group, you shouldn't use brackets, and no need for using $2 for the first match instead of $1.

  • If you are on 1.9/develop, you can now define recursive routes to implement this:

  • Hello,

    Thank you.

    but, it doesn't seem to work.

    And how use this : \Router::get('event_index') ? I means, how the system choose between events and eventements ?
  • You can't create mutliple routes with the same name, so that problem doesn't exist.

Howdy, Stranger!

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

In this Discussion