Welcome Guest, Not a member yet? Register   Sign In
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0)
#3

[eluser]ejangi[/eluser]
I wanted to do something quite similar naruto, here's what I do.

In my config/routes.php file I added this line:
Code:
$route['(:any)/(:any)\.(:any)'] = "$1/$2";
so I allow different file types to be put into the URI.

And then I added an "overwrite" class for the URI library. So, create a file in your "libraries" folder called MY_URI.php, with the following:
Code:
class MY_URI extends CI_URI {
    
    
    /**
     * Constructor
     *
     * @return void
     */
    public function MY_URI()
    {
        parent::CI_URI();
    } // MY_URI()



    /**
     * Grab the requested file format fromt he URI
     * This requires an addition to the routes.php file:
     *
     * $route['(:any)/(:any)\.(:any)'] = "$1/$2";
     * @return string
     */
    public function format($default_return = false, $separator = '.')
    {
        $format = $default_return;
        if (count($this->router->segments)) {
            $last_segment = explode($separator, end($this->router->segments));
            if (count($last_segment) > 1) {
                $format = strtolower(end($last_segment));
            }
        }
        return $format;
    } // format()

} // END class MY_URI

So, now in my controller methods I can do something like this:
Code:
if ($this->uri->format() == 'wsdl') {
    // Do web service stuff
} else {
    // Normal HTML stuff.
}

I hope this helps.


Messages In This Thread
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-07-2008, 07:01 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-07-2008, 08:33 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-07-2008, 09:14 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-08-2008, 12:06 AM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-08-2008, 10:24 AM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-08-2008, 05:19 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 01-08-2008, 08:23 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-07-2008, 06:15 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-07-2008, 06:18 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 06:50 AM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 04:24 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 07:22 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 07:26 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 08:25 PM
Multiple URL Suffix (SOLVED - UPDATED for CI 1.6.0) - by El Forum - 02-20-2008, 08:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB