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.
The routes.php:
$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";
This works perfectly, but i have an area called “blog”, inside the Blog CI_Controller is a function that grabs an article from database:
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. In the language files i have my variables saved like this:
$lang['menu.blog'] = "Blog";
In the blog view the $lang variable is loaded:
<?=lang('menu.blog')?>
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:
$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.
I may not be understanding what you're asking but it seems like you could do:
That should capture the different language but still route you to the blog article via the id.