Welcome Guest, Not a member yet? Register   Sign In
Routing: Passing entire expression as unique argument
#3

[eluser]mddd[/eluser]
The routing feature is really only a string handling functon. The examples you give, like
Code:
$route[‘controller/method/(.*)$’] = “controller/method/$1”;
are not changing the string at all! After this route, the url is exactly the same!

The problem is that you are trying to pass a string containing slashes inside the url. That doesn't work because CI chops it up.
I see two options: one is to get the entire segment array and chop off the first part (controller, method). Like so:
Code:
// imagine the requested url is /controller/method/path/to/file
$path = array_slice( $this->uri->segment_array(), 2 );
// now $path will be an array containing path, to, file
$path = join('/', $path);
// now $path will be path/to/file

The other option is to encode the path to that it doesn't contain slashes anymore. Then CI will see it as one part. Like so:
Code:
// imagine the requested url is encoded: /controller/method/path % 2f to % 2f file
$path = $this->uri->segment(3);
// now $path will be path % 2f to % 2f file
$path = urldecode($path);
// now $path will be path/to/file
Note: the spaces in the url in this example are there because otherwise the forum translates the url encoded string.


Messages In This Thread
Routing: Passing entire expression as unique argument - by El Forum - 04-06-2010, 05:02 AM
Routing: Passing entire expression as unique argument - by El Forum - 04-06-2010, 05:31 PM
Routing: Passing entire expression as unique argument - by El Forum - 04-07-2010, 03:20 AM
Routing: Passing entire expression as unique argument - by El Forum - 04-07-2010, 03:54 AM
Routing: Passing entire expression as unique argument - by El Forum - 04-07-2010, 04:02 AM
Routing: Passing entire expression as unique argument - by El Forum - 04-07-2010, 09:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB