开发者

CodeIgniter Url Rewrite (language dependent)

So, i have my .htaccess, my controllers, everything is going fine. I added localization, so now i have Portuguese(Default), English and Italian.

I am using the _lang files in the appplication/languages directory, i am using session->userdata('lang') and everything works fine. My controllers are named with portuguese words, after the top menu. What i'm looking for is:

to rewrite my url, changing the name of the controller, depending on the session->userdata('lang').

Is this even possible? how?

Thank you

So i am trying, as InFog suggested, in the routes file:

if ($this->session->userdata('lang') == 'english') { 
    $route['novidades/([a-z]+)'] = 'news/$1'; 
}

but i just get a blank screen when i open the application.

And i've tried it without the if clause, and nothing happens, when i go to

http:开发者_JS百科//localhost/myapp/novidades

the url stays the same


You can solve this using CodeIgniter Routes. You can do it editing the file 'system/application/config/routes.php:

$route['news/([a-z]+)'] = 'noticias/$1';

This way an URL like '/news/run-fools' will be remaped to 'noticias/run-fools'. Now you can have just one controller =)

Good Luck


Override CI_Router to translate the name in the fetch_class() method to change controllers. Override fetch_method() to change methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜