• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help deal with routes ?!

#1
Question 
[/url][url=https://codeigniter4.github.io/userguide/incoming/routing.html#placeholders]I already asked a similar question, but alas, the response I never received.

Reading the documentation on the link, I notice that the placeholder "{locale} " CANNOT be used as a route for example:
PHP Code:
$routes->add('{locale}/news/post/id''App\News::posts\$1', ['as' => 'Select_News']);
$routes->add('{locale}/news/main''App\News::posts', ['as' => 'All_News']); 
But clicking on another link, there I see that this placeholder CAN be used as a stand, which I do...
Only here there is one problem when I use method "->back('Select_News');" in the browser line appear these strange characters "http://example.ru/%7Blocale%7D/News/Post/1", although should be EN or RU, in dependence where initially I was.
How can I fix this ?
I would change this world, but God doesn't give me the source.
Reply

#2
See https://github.com/codeigniter4projects/website2 for a working example of localization with the locale part of the URI.
Reply

#3
(09-20-2019, 07:12 AM)ciadmin Wrote: См. https://github.com/codeigniter4projects/website2 для рабочего примера локализации с языковой частью URI.
Oh, I seem to have missed the news about this repository. Thanks for the answer !
I would change this world, but God doesn't give me the source.
Reply

#4
Good day !

Yesterday I looked into the project I was recommended above where I saw that in the configuration file "routes.php" registered routes in two versions with localization and exactly the same only without localization "{locale}", I repeated it in my project with only one difference, I used a group. But I had a question:

This is best practice because the amount of code gets doubled, and if it's not best practice, is there a way to fix this using my data as an example (see my screenshot). ?


Attached Files Thumbnail(s)
   
I would change this world, but God doesn't give me the source.
Reply

#5
The first set, without localization, is to remediate requests coming in to soething other than the homepage, but without the link. This could be bookmarked links for instance. This solves a problem we saw when converting to the localized app. It might not be the most elegant solution, but I can live with it.

The second set of routes, with localization, are the "normal" ones.

The language dropdown is driven by the supportedLocales property in app/Config/App.php. If the user chooses a language with missing or no translations, the app falls back to English.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.