CodeIgniter Forums
Help deal with routes ?! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Help deal with routes ?! (/showthread.php?tid=74415)



Help deal with routes ?! - Digital_Wolf - 09-20-2019

[/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 ?


RE: Help deal with routes ?! - ciadmin - 09-20-2019

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


RE: Help deal with routes ?! - Digital_Wolf - 09-20-2019

(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 !


RE: Help deal with routes ?! - Digital_Wolf - 09-21-2019

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). ?


RE: Help deal with routes ?! - ciadmin - 09-21-2019

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.