Welcome Guest, Not a member yet? Register   Sign In
prepending vars (useful tip when working with subdomains or multilanguage sites)
#1

[eluser]smoku[/eluser]
Hello!

I moded CI a little bit because I needed to prepend var.

With this mod you can create links like:
http://www.domain.com/index.php?user=USE...er/method/....

I needed this in order to create user sites with subdomains:
USERNAME.domain.com/controller/method => domain.com/index.php?user=USERNAME&/controller/method/

But it could be also very useful with multilanguage sites.
You can easily redirect:
domain.com/LANG/controller/method => domain.com/index.php?lang=LANG&/controller/method

query_strings must be TURNED ON!

----------------------------

Here is the code:

Open Router.php

In function _set_route_mapping() at the begining

change:
Code:
// Fetch the complete URI string
$this->uri_string = $this->_get_uri_string();

to:
Code:
// Fetch the complete URI string
$this->uri_string = $this->_remove_query_strings($this->_get_uri_string());

Add this function to router.php:
Code:
function _remove_query_strings($string)
{
    $start = strpos($string, "/");
    if ($start == 0)
    {
       return $string;
    }
    else
    {
        $end = strlen($string);
        $length = $end-$start;
        return substr($string, $start, $length);
    }
}

I don't know if anyone finds this helpful but I needed this in my project so I'm posting this, because I couldn't find it...


Messages In This Thread
prepending vars (useful tip when working with subdomains or multilanguage sites) - by El Forum - 01-24-2008, 06:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB