0

So being locate at this url (as an example) : http://localhost/codeigniter-app/en/results?search_query=data

uri_string doesn't return the needed path

["uri_string"]=>
  string(10) "en/results"

and the expected:

["uri_string"]=>
  string(10) "en/results?search_query=data"

Some of my config.php

$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = false;

Any ideas?

Edit:

The problem is found when using http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n library

Alex
  • 7,538
  • 23
  • 84
  • 152

3 Answers3

1

You've got querystrings turned off - last time I used CI (back on 1.7.x), it ignored them. Try turning them on:

$config['enable_query_strings'] = true;

Josh
  • 1,261
  • 2
  • 18
  • 34
1

I believe you'll have to use $this->input->get() to access the query string which, based on your example, would produce:

array(1) { ["search_query"]=> string(4) "data" }

Also, it's worth including this from the documentation:

Please note: If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
  • the thing is that I don't need to get the `$_GET` data, but the url so I use it to change the language parameter. – Alex Feb 26 '12 at 13:29
  • @w0rldart: I understand, but as I mentioned, I think the only way to get the query string is with `$this->input->get()`. I think you'll have to use that in conjunction with `uri_string` to build the "complete" URL. – Colin Brock Feb 26 '12 at 16:16
  • I kinda need `uri_string` to work because the url structure isn't always the same – Alex Feb 26 '12 at 20:03
  • @w0rldart: I understand your dilemma, but `uri_string` simply does not contain query string data. To get the query string, you'll have to use `$this->input->get()` or perhaps `$_SERVER['QUERY_STRING']` and build the full URL yourself. [Please see the accepted answer to this question](http://stackoverflow.com/q/4160377/30433) for advice on creating a helper function to do that. – Colin Brock Feb 26 '12 at 20:27
0

I ended adding this in application/core/MY_Lang.php where I needed to get the correct path:

if(preg_match('/results/', $this->uri))
{
    $this->uri = $this->uri.'?'.$_SERVER['QUERY_STRING'];
}

bellow: $this->uri = $URI->uri_string();

Alex
  • 7,538
  • 23
  • 84
  • 152