Multi language using Codeigniter

2019-09-14 21:16发布

问题:

Confuse to use multi language using codeigniter.

Example, my domain is www.example.com then I have 3 language, English (en), Japan (jp), China (cn) and now I need access every language like:

www.example.com/en/bla-bla/
www.example.com/jp/bla-bla/
www.example.com/cn/bla-bla/

but, I dont want make controller every language. have you idea ?

回答1:

You should use routing to pass language as variable to your controller to display content in correct language. For example you can do it like that: In application\config\routes.php

$route['(:any)/product'] = 'product/index/$1';

In controller:

class Product extends CI_Controller
{
    public function index($lang = '') {
        //for link http://example.com/en/product there will be 'en' in $lang
    }
}

Documentation: https://www.codeigniter.com/user_guide/general/routing.html



标签: codeigniter