Welcome Guest, Not a member yet? Register   Sign In
Optionally enable standard query string based URLs
#1

[eluser]garaget[/eluser]
I have been trying to get only ONE of my functions to load with standard query string with no luck. I played with both the config and route files only to come with more errors. If anyone has any suggestions I would appreciate it Smile

URL
www.your-site.com/class/function?c=controller&m=function

route.php
Code:
$route['class/function?:any'] = "class/function/$1";

config.php
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-?=&';
$config['enable_query_strings'] = TRUE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
#2

[eluser]xwero[/eluser]
I think you better convert the query string of the method in a pre_system hook.
Code:
function get_to_segments()
{
   if(substr($_SERVER['PATH_INFO'],1) == 'controller/method')
   {
       header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'/'.implode('/',$_GET));

       exit;
   }
}
Then you don't have to enable the query strings and you don't have to add extra characters to the allowed_characters setting.
#3

[eluser]garaget[/eluser]
Thanks XWERO.. You are always here to help us Newbs out. You should change your SN to xHERO. Smile
#4

[eluser]Dam1an[/eluser]
Thanks Xwero, I was wondering how to get a nice, clean combination of URI segments and query strings Smile
#5

[eluser]xwero[/eluser]
the code doesn't mix path segments with query strings. It processes the query string to path segments before it reaches CI. The function is meant to be used when you want your app to have all path urls.

If you want to prevent CI from fetching the query string you set the uri_protocol to path_info/orig_path_info/request_uri. When you need the query string in one of your methods you just add
Code:
parse_str($_SERVER['QUERY_STRING'],$_GET);
and you can use the global.
#6

[eluser]Unknown[/eluser]
thanks for this thread,it helped me a lot
#7

[eluser]Thorpe Obazee[/eluser]
Nice. This might be helpful to me someday Smile bookmarked.

EDIT: So this thing redirects to the 'correct' path whenever it encounters the query string your looking for. Maybe it should be noted that this only works when you set the uri_protocol to PATH_INFO and ORIG_PATH_INFO.
#8

[eluser]ricick[/eluser]
This is awesome. It really should be in the user guide.
#9

[eluser]ricick[/eluser]
This breaks with the 1.7.2 upgrade under php 5.3
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: PATH_INFO

Filename: hooks/hooks.php

Line Number: 5




Theme © iAndrew 2016 - Forum software by © MyBB