Closed rafatrace closed 9 years ago
Hi @rafamds, I don't think we can call it a conflict. From the framework's point of view, ROUTES
can contain any kind of routes (with or without language prefix), so an automatic prefix would not fit all situations.
Also note that the core reroute
function works well with named routes. See :
$f3->reroute('@contact');//reroute to the current language "contact" route (i.e prefixed)
I understand, thanks for the exaplanation. Cheers
Hi @rafamds,
After giving it more thought, I came to the conclusion that the plugin should provide a mean to quickly localize existing monolingual projects, even those with unnamed routes.
For that purpose, I've added a reroute
method to the plugin, which automatically prefixes the provided URI, if needed:
$ml->reroute('/en/contact'); // OK
$ml->reroute('/contact'); // OK => reroute to /xx/contact where xx is the current language
If you don't want to rewrite all your $f3->reroute
into $ml->reroute
, you can simply use the framework's ONREROUTE
hook:
$f3->set('ONREROUTE',function($url,$permanent) use($f3,$ml){
$f3->clear('ONREROUTE');// avoid infinite loop
$ml->reroute($url,$permanent);
});
After which $f3->reroute('/contact')
will reroute to /xx/contact/
.
NB: I've updated the docs.
Wow, nice work @xfra35, this was exactly what I was looking for.
I prefer to use $ml->reroute()
and rewrite everything, and I advice everyone to do this, because in this way you can spot a diference between $f3
and $ml
rerouting, and you or other developer that comes to help know that theres a difference.
Excellent work mate, glad to know you're improving this. Cheers.
Hello mate, does rerouting function from f3 conflicts with multilang?
I got this line of code:
This reroutes to
app-path.com/route
insted ofapp-path.com/en/route
.Should I use?
It was nice if this was automatically ;)
Thanks for your time, cheers.