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

[eluser]Fabdrol[/eluser]
Hi Nalorin,

Well, you could use my solution, but I recon it'll be useless when you have a variable amount of parameters.
Here's an update for it:

In config/routes.php
Code:
// replace the dots by the number of variables you'll need, until $n
// parameter one is always the city, two always the controller, three the method. $4 to $n are the max number of parameters
$route['(:any)/(:any)/(:any)/.../(:any)'] = "reroute/to/$1/$2/$3/.../$n";

Create a controller: controllers/reroute.php
Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed!');

class Reroute extends Controller {

    public function __construct() {
        parent::__construct();
        
        $this->load->helper('url');
    }
    
    public function to() {
        $args = func_get_args();
        $city = $args[0];
        $uri = '';

        // set the city in a session.
        $this->session->set_userdata('city', $city);

        for($i = 1; $i < count($args); $i += 1) {
            $uri .= $args[$i] . '/';
        }

        redirect($uri);
    }

}

The reroute class' to() method fetches the arguments passed to the method, caches the first parameter as the city, and parses the rest into a redirect url (to another class, method and parameters)

Example:
Code:
User requests:
www.mysite.com/chicago/category/product/876/pictures/

The route routes this request to the to() method of the reroute class, and this method fetches an array containing:
[0] => chicago,
[1] => category,
[2] => product,
[3] => 876,
[4] => pictures

The to() method sets a session containing the city, and parses a redirect url:
redirect('category/product/876/pictures');


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