CodeIgniter 和 i18n 库

发布于 2024-12-28 00:37:50 字数 1296 浏览 2 评论 0原文

你好论坛,在使用 CI 2.0.3 和国际化 (i18n) 库时,我遇到了这个问题。我在这里读过类似的帖子,但他们没有解决我的问题。希望这里有人能指出我正确的方向。

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";  

这工作得很好,但我有一个名为“博客”的区域,博客 CI_Controller 内部是一个从数据库中获取文章的函数:

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

  $this->load->view('article_view',$data); 
 }  

太棒了,也可以工作。结果是一个类似 /en/blog/article/1 的 URL。 在语言文件中,我的变量保存如下:

$lang['menu.blog'] = "Blog"; 

在博客视图中,加载了 $lang 变量:

<?=lang('menu.blog')?> 

打开文章时出现问题,语言文件中的 var 根本没有加载。 http://localhost/ 而不是“博客”。我猜这与路由有关。因此,如果对于像 /en/blog 这样的 URL,我会:

$route['^(en|de|ru)/(:any)'] = "$2"; 

所有其他 URL 都可以正常工作并正确从语言文件加载变量。

但是我如何处理像 /en/blog/article/1 这样的 URL?我的思考方向正确吗? 欢迎提出建议。

谢谢。

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)

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.

] = $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:

Wonderful, works also. The result is an URL like /en/blog/article/1.
In the language files i have my variables saved like this:

In the blog view the $lang variable is loaded:

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:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2025-01-04 00:37:50

我可能不明白你在问什么,但你似乎可以这样做:

$route['^(en|de|ru)/blog/article/(:any)']

这应该捕获不同的语言,但仍然通过 id 将你路由到博客文章。

I may not be understanding what you're asking but it seems like you could do:

$route['^(en|de|ru)/blog/article/(:any)']

That should capture the different language but still route you to the blog article via the id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文