Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Route and lang
remi
November 2023
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
Harro
November 2023
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.
Harro
November 2023
If you are on 1.9/develop, you can now define recursive routes to implement this:
https://fuelphp.com/dev-docs/general/routing.html#/recursion
remi
November 2023
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 ?
Harro
November 2023
You can't create mutliple routes with the same name, so that problem doesn't exist.
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,089
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
261
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
November 2023
remi
November 2023