Welcome Guest, Not a member yet? Register   Sign In
Troubles with URI class
#1

[eluser]jakelehner[/eluser]
Hi all ... I've done some searching on here and haven't found an answer yet. I'm having a hell of a time with the ruri_to_assoc and uri_to_assoc functions, and hope someone can help me out here.

The following scenario happens both in CI 2.0.1 and CI 2.1.0.

I have the following route defined:

Code:
$route['user/(:any)'] = "user/index";

Obviously, the goal here is to not include the method (index in this case) in the URL string. The uri functions mentioned above don't seem to be working as expected. When I access the following URL:

/user/id/3/format/json (which routes to /user/index/id/3/format/json)

I get the following:

Code:
$this->uri->ruri_to_assoc()

generates

Code:
Array
(
    [3] => format
    [json] =>
)

and

Code:
$this->uri->uri_to_assoc()

generates

Code:
Array
(
    [3] => format
    [json] =>
)

I'm confused why ruri is returning the same as uri. Here's where it gets interesting ...

both of the following

Code:
$this->uri->ruri_to_assoc(1)
and
$this->uri->uri_to_assoc(1)

return

Code:
Array
(
    [user] => index
)

then

Code:
$this->uri->ruri_to_assoc(2)
and
$this->uri->uri_to_assoc(2)

both return

Code:
Array
(
    [index] =>
)

BUT ...

Code:
$this->uri->ruri_to_assoc(3)
and
$this->uri->uri_to_assoc(3)

both return

Code:
Array
(
    [3] => format
    [json] =>
)


wtf? Am I missing something here? It looks like the ruri and uri functions are doing the same thing. I also don't understand why it looks like both functions are counting the PRE-routed url (by counting 'index' as a segment) until I specify the start segment as 3 ... in this case BOTH functions decide to use the post route URL and view 'id' as the method rather than the first segment.

Please telling me I'm missing something easy here.
#2

[eluser]jakelehner[/eluser]
Ok ... I found my first problem. My route was wrong. I changed it to:

$route['user/(:any)'] = "user/index/$1";

and it *almost* works ...

now if I go in to the URI library and comment out the block of code that does the caching:

Code:
if (isset($this->keyval[$n]))
  {
   return $this->keyval[$n];
  }

it works ... but if I leave the cache block in, it does not.

Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB