Welcome Guest, Not a member yet? Register   Sign In
URI localization: Translating the uri-segments
#7

[eluser]Fabdrol[/eluser]
I don't think you need to go through all that trouble creating a hook..
Personally I'd do something like this:

Routes config:
Code:
// reroute to controller 'tomtom', method 'map', with arguments $1 and $2.
  $route['(:any)/(:any)'] = 'tomtom/map/$1/$1';

Tomtom.php controller
Code:
class Tomtom extends Controller {
    
    function __construct() {
      parent::Controller();
      $this->load->library('database');
    }

    function map($lang, $method) {
      $this->db->where('lang', $lang);
      $get = $this->db->get('local_methods');
      
      if($get->num_rows() <= 0) {
        // this lang is not known. throw error!
        log_message('error', 'language not found, redirecting to default language');

        // map to the global controller, doing the real action.
      } else {
        // language found. continue
        $language = $get->row();
        if($language->{$method} !== false) {
          // the method exists for this language. map to the 'real' method.
        }
      }
    }

  }

In short, what your code does..
1. You send an url like: "nl/gereedschappen/" to the system.
2. The Router maps that url to the language handler controller.
3. The TomTom controller checks the db if the language exists, and if so, if the method exists.
4. The TomTom controller takes the 'real' data handling method and controller to which the localized controller should point from the database and sends the user through that controller
5. Be sure not to use redirect(), since it'll change the url!!

Any questions, or want more code examples? Drop me a line at fabian [at] dotbrilliance [dot] nl

succes!
Fabian


Messages In This Thread
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 04:39 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 05:30 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 06:17 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 06:54 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 07:43 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 08:17 AM
URI localization: Translating the uri-segments - by El Forum - 12-02-2009, 10:27 AM
URI localization: Translating the uri-segments - by El Forum - 08-11-2010, 03:03 PM
URI localization: Translating the uri-segments - by El Forum - 08-11-2010, 04:20 PM
URI localization: Translating the uri-segments - by El Forum - 08-11-2010, 04:58 PM
URI localization: Translating the uri-segments - by El Forum - 08-11-2010, 10:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB