0

I've got a small problem with routing in kohana 3.2. I want to create a simple blog with multiple language support.

I want to create links like this:

  • pl.yourwebsite.com/kontakt
  • en.yourwebsite.com/contact
  • xx.yourwebsite.com/sometranslation of controller above

I set up a simple controller for contact and routes, but when it comes to route i must set static route, which is quite a bad solution. For example:

for pl lang:

Route::set('kontakt', 'kontakt(/<action>(/<id>(/<id2>(/<id3>))))')
    ->defaults(array(
        'controller' => 'contact',
        'action'     => 'index',
    ));

It works when I use domain.com/contact and domain.com/kontakt, but when I will have 20+ controllers and 3 langugage; that will be 60+ routes == bad solution.

I appreciate any help.

4

1 回答 1

1

您至少可以将单个页面的翻译组合在一起,但为此您仍然需要每页至少有一条路线。

此示例使用正则表达式来匹配<page_name>url 的一部分:

Route::set('kontakt', '<page_name>(/<action>(/<id>(/<id2>(/<id3>))))',
           array('page_name' => '(contact|kontakt|contatto)'))
    ->defaults(array(
        'controller' => 'contact',
        'action'     => 'index',
    ));

还要考虑你可以在设置一个回调函数时指定一个回调函数Route,如果它找到匹配的路由,可以返回应该调用的控制器和动作。这允许您运行自己的代码并确定要调用的控制器/操作。请参阅手册中的Lambda/回调路由逻辑部分。

于 2013-08-08T23:23:39.313 回答