CodeIgniter Forums
route_to & {locale} - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: route_to & {locale} (/thread-75781.html)



route_to & {locale} - korgoth - 03-16-2020

Hello!

I have incorporated {locale} in my routes for a bilingual website. 

The actual routing seems to work if i add: 

PHP Code:
$routes->get('{locale}/contacts''Contacts::index', ['as' => 'contacts']); 

i am able to access website.com/en/contacts and website.com/de/contacts all with proper locale set in the request. 

The problem is when i try to use a reverse route so that i can make links in my views.  When i try:

PHP Code:
<?= route_to('contacts'?>

it returns "/{locale}/contacts" as a string - and i am expecting that the {locale} part will be replaced by the current locale set in the request so that when i am visit website.com/en/contacts that reverse route would be resolved to "/en/contacts" string? 

Are my expectations wrong?  How should i proceed to generate URLs in my views then?  

I could of course get the string from route_to() function and manually replace the {locale} but that just doesnt seem right - i really thought that this thing should be possible/working by default


RE: route_to & {locale} - MGatner - 03-23-2020

Have you tried this since https://github.com/codeigniter4/CodeIgniter4/pull/2715 ?


RE: route_to & {locale} - korgoth - 03-23-2020

(03-23-2020, 09:09 AM)MGatner Wrote: Have you tried this since https://github.com/codeigniter4/CodeIgniter4/pull/2715 ?

Thanks for the info. I am kind of waiting for a release from CI with this implemented, or am i wrong to wait about that?


RE: route_to & {locale} - MGatner - 03-23-2020

Up to you! Next release has no announced schedule so I can't advise on how long that might be.