• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mix normal URL's and standard query strings

Is it possible to mix normal url's and standard query strings? For example due to an oauth callback, I will need to be able to accept the following:


Is this sort of url structure possible with code igniter 2.0?


It is and I use it Smile

My setup is as follows:
// url: http://site.com/controller/function/?var=val&var2=val2

$config['uri_protocol']    = 'QUERY_STRING';

// in my controller's __construct() function, I have the following to parse the $_GET properly
parse_str(substr(strrchr($_SERVER['REQUEST_URI'], "?"), 1), $_GET);

[eluser]Peter Denk[/eluser]
It is!
I just spent half a day figuring it out.

First of all, be sure to download the latest version of CI 2.0 Reactor or at least check that line 52 in system/core/input.php reads:

$this->_allow_get_array = (config_item('allow_get_array') === TRUE);

Also check in config.php that you have:

$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = FALSE;

Then you should be able to read the query-string with:

$variable = $this->input->get( 'variable' );

or if you want XSS-filtering:

$variable = $this->input->get( 'variable', TRUE );

I you prefer to always do XSS-filtering set

$config['global_xss_filtering'] = TRUE;

in config.php

get() is part of the Input-class (http://ellislab.com/codeigniter/user-gui...input.html)

Good luck!

For both of the replies I am still having the same problem. If i just have controller/method the correct controller is loaded. If I do controller/method?variable, CI 2.x will load the default controller instead of the one int he url.


Is this on code igniter 2.x? I don't seem to be able to get that to work.

@Peter Denk

Are those the default config settings? As described above, I can't get the correct controller to load. It always goes to the default one.

[eluser]Peter Denk[/eluser]
Have you tried setting
$config['uri_protocol'] = 'PATH_INFO';

Paste your code!

[eluser]Mike One[/eluser]
During the upgrade from 1.7.2 to 2.0.2, I encountered a similar problem. Basically, my code didn't have access to $_GET anymore in 2.0.2, while this worked fine in 1.7.2 (using $config['enable_query_strings'] = TRUE; in the config).

Seeing that this breaks in 2.0.2, I feel this is missing in the upgrade document. I took me a while to find out how to resolve this (by analyzing the Input class) but the answer for me (as Peter stated above) was indeed to ALSO add:

$config['allow_get_array'] = TRUE;
to the config.

Maybe this should be added to the upgrade docs?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

Users browsing this thread:
1 Guest(s)

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.