开发者

Using multiple language views for the same controller in CodeIgniter

How do I use multiple language views in a controller according to the url parameter? I have a english version of a w开发者_StackOverflowebsite in CodeIgniter.I want to make Greek and Arabic version of this website without changing the models and controllers.Anybody know how to do it so that i can get CodeIgniter to display different views for the same controller according to the language parameters in the URL. like the URL below

http://www.example.com/en/ for English

http://www.example.com/ar/ for Arabic

http://www.example.com/gk/ for Greek

Thanks in advance


Try with this:

Internationalization (i18n) library for CodeIgniter

I've used it in my project with little modification and it is really great.


You can choose to do the following, if you have different templates/views for each language.

$lang = $this->uri->segment(1);

$this->load->view("view_folder/".$lang."/main_page");

Then you can store each different languages like this:

view_folder/en/main_page.php
view_folder/ar/main_page.php
view_folder/gk/main_page.php

Please keep in mind to edit the routes, so you can use the same controller. I would use Regex in the routing system, like this:

$route['([a-z_A-Z]+)/controller'] = 'controller';

Then when you do http://www.example.com/en/controller , you should be redirected to the controller and $this->uri->segment(1); will be available for language selection.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜