Question

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.

Était-ce utile?

La solution

You can at least group the translation of single pages together, but for this you would still need to have at least one route per page.

This example uses a regex to match the <page_name> part of the url:

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

Also consider that you can specify a callback function when setting a Route which, if it finds a matching route, can return the controller and action which should be called. This allows you to run your own code and determine which controller/action you want to call. See the Lambda/Callback route logic section in the manual.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top