Welcome Guest, Not a member yet? Register   Sign In
Routes and i18n [SOLVED]
#1

[eluser]Unknown[/eluser]
Hello Forum,

while working with CI 2.0.3 and internationalization (i18n) library, i've run into this problem. I've read similar posts here, but they did not solve my issue. Hope somebody here can point me into the right direction.

1. routes.php

Code:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['scaffolding_trigger'] = "";

// '/en', '/de', '/ru' URIs -> use default controller
$route['^(en|de|ru)$'] = $route['default_controller'];  

// URI like '/en/about' -> use controller 'about'
$route['^(en|de|ru)/(:any)'] = "$2";

2. This works perfectly, but i have an area called "blog", inside the Blog CI_Controller is a function that grabs an article from database:

Code:
public function article()
{
  $this->db->where('id', $this->uri->segment(4));
  $data['query']= $this->db->get('blogentries');
      
  $this->load->view('article_view',$data);
}

Wonderful, works also. The Result is an URL like /en/blog/article/1.

3. In the language files i have my variables saved like this:
Code:
$lang['menu.blog'] = "Blog";

In the Blog View the $lang variable is loaded:
Code:
<?=lang('menu.blog')?>

4. The problem occures while opening an article, the var from the language file is not loaded at all. http://localhost/ instead of "Blog". I guess it has to do with the routing. So if for an URL like /en/blog i would have:
Code:
$route['^(en|de|ru)/(:any)'] = "$2";

All other URLs work perfectly and load the variables from the language file correctly.

But how can i handle URLs like /en/blog/article/1? Am i thinking in the right direction?
Suggestions are appreciated.

Thank you.
#2

[eluser]Unknown[/eluser]
Ok, finally i've found the solution.
The $lang variable simply had to be loaded within the function.
Probably the best way is to declare this globally in the next step.

Code:
public function index()
{
        $this->lang->load('headers'); //<-- BANANAS!
        $this->load->view('home_view');          
}


Cheers




Theme © iAndrew 2016 - Forum software by © MyBB