Welcome Guest, Not a member yet? Register   Sign In
GET params not passed when using URI ROUTE class
#1

[eluser]Future Webs[/eluser]
Im using the latest DEV version of codeigniter and attempting to create SEO urls with the URI routing class but it seems that my GET params are being ignored and not sure which direction to go in.

I already use GET params across the rest of the site without any problems and have query_strings enabled.

Here is an example of a route im trying to use.

Code:
$route['controller/nice-seo-url-([a-z]+)-with-keywords']  = 'controller/index/?key=$1&var1=that&var2=this';

The result is that I land on the correct index page for the controller but the GET params are not passed.

Ive tried to log the input->get() output and can see that the get is empty.

Am i missing something or is the URI class just not built to do what im trying to do.

Thanks in advance and if im not describing this well let me know.
#2

[eluser]InsiteFX[/eluser]
Add this to your application/config/config.php in permitted uri chars.

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&?';

Also make sure query strings are enabled.
#3

[eluser]CroNiX[/eluser]
I think enabling query strings will only work if the whole request is a query string without using any traditional segments, including the controller/method (&c, &m by default).
See how it affects the routing:
https://github.com/EllisLab/CodeIgniter/...r.php#L160
If enabled, it expects the controller/method $_GET variables to be set.

Try disabling query strings in config if you want to use CI segments for the main operations of the site. You can still use query strings in the url in addition to the segments by allowing '&?' in $config['permitted_uri_chars'] as InsiteFX suggested.
#4

[eluser]Future Webs[/eluser]
Firstly thanks for taking a look at this and getting back to me. Very much apreciated.

I just double checked my config settings and i have

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

My mistake earlier !

I already use GET params alongside the standard segment style url for filtering search results etc and that works fine.

for example

Code:
http://mysite.com/controller/method/?keys=this&cat=3

The problem only seems to arise when I try and create a custom route to give me better SEO style urls in some instances. It sends me to the correct /controller/method but strips the extra GET params i add to the route.

I tried to add &? to the permitted_uri_chars array but that did not help.
#5

[eluser]CroNiX[/eluser]
Because you are taking the requested URI (the first part of the route), transforming it into variables, and passing it to a controller/method (2nd part of route). At that point, it's not a URL anymore and there are no $_GET variables unless they were present in the first part of the route. You can have a query string in the first part of the route, but not the part where it gets sent to. It's not a "redirect".
Code:
$route[the real url] = translated controller/method/arguments
not
Code:
$route[the real url] = a different url

You could try and simulate the $_GET, something like this:
Code:
$route['controller/nice-seo-url-([a-z]+)-with-keywords']  = 'controller/index/key=$1&var1=that&var2=this'; //remove the ?

Code:
Your_controller extends CI_Controller {
  function index($params = null)
  {
    if ( ! is_null($params))
    {
      $params = parse_str($params);  //Should now be same as $_GET
      //print_r($params);
      //array('key' => whatever $1 was, 'var1' => 'that', 'var2' => 'this')
    }
  }
}
#6

[eluser]Future Webs[/eluser]
Thanks again,

I guess I could go with the traditional mod_rewrite / htaccess method




Theme © iAndrew 2016 - Forum software by © MyBB