Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Altorouter multilingual routing

Is it possible to use Altorouter to create a multilingual routing setup? I'd want to send a variable with the target file (so that it displays different contents when viewed), e.g. -

$router->map('GET','/th/work/sample', 'work/sample.php', 'sample', 'th');

But that fifth parameter isn't available. Is there any workaround for this?

like image 309
Staffan Estberg Avatar asked Oct 19 '16 03:10

Staffan Estberg


1 Answers

You can use pattern-matching in the URL to achieve this, if the your language URLs are regular enough.

According to the documentation, defining the route

$router->map('GET', '/[:lang]/work/sample', 'work/sample.php', 'sample')

will capture 'th' in $lang when the '/th/work/sample' URL is hit. If you need more complex pattern matching, custom regexes can be also be specified.

like image 88
gbe Avatar answered Sep 16 '22 13:09

gbe