[eluser]domonline[/eluser]
Thought I share this as I found it incredibly frustrating that I couldn't mix using paths and query strings and a situation arose that demanded this with very short time frame to sort it out.
If you want urls like:
Code:
http://www.yoursite.com/segment/and_so_on/?query=1&query1=2
This'll work like you'd expect it.
e.g. you can still use :
Code:
$this->uri->segment(2)
// but you can also use
$_GET['query']
and
Code:
http://www.yoursite.com/segment/and_so_on // Works
http://www.yoursite.com/index.php?c=food&m=menu // Works and pulls up crontroller/method
http://www.yoursite.com/segment/and_so_on/?query=working // Also works
You need to create a file called MY_URI.php in your system/application/libraries/ folder
Put the following in it, it's really simple just overrides one method.
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_URI extends CI_URI {
function MY_URI() {
parent::CI_URI();
}
// --------------------------------------------------------------------
/**
* Override the _parse_request_uri method so it allows query strings through
*
* @access private
* @return string
*/
function _parse_request_uri()
{
if ( ! isset($_SERVER['REQUEST_URI']) OR $_SERVER['REQUEST_URI'] == '')
{
return '';
}
$uri = explode("?",$_SERVER['REQUEST_URI']); // This line is added to the original
$request_uri = preg_replace("|/(.*)|", "\\1", str_replace("\\", "/", $uri[0])); // This line changed
// Everything else is just the same
if ($request_uri == '' OR $request_uri == SELF)
{
return '';
}
$fc_path = FCPATH;
if (strpos($request_uri, '?') !== FALSE)
{
$fc_path .= '?';
}
$parsed_uri = explode("/", $request_uri);
$i = 0;
foreach(explode("/", $fc_path) as $segment)
{
if (isset($parsed_uri[$i]) AND $segment == $parsed_uri[$i])
{
$i++;
}
}
$parsed_uri = implode("/", array_slice($parsed_uri, $i));
if ($parsed_uri != '')
{
$parsed_uri = '/'.$parsed_uri;
}
return $parsed_uri;
}
}
?>
In your system/application/config.php file you need to enable query strings so $_GET isn't unset and set the uri protocol to REQUEST_URI. With some digging around I'm sure you could get AUTO and the other methods to work as well but just didn't have the time or the need.
Code:
$config['uri_protocol'] = "REQUEST_URI";
$config['enable_query_strings'] = TRUE;
I hope this is of help to someone