-
Notifications
You must be signed in to change notification settings - Fork 7.6k
alternative to GET
By default code ignitors $_GET is unset. What do you do if you want to have the ease of query strings and uri segments at the same time, without having to optionary enable query strings? Tyy this simple help function.
Create a simple helper and call it request. Use ths function function getRequests() { //get the default object $CI =& get_instance(); //declare an array of request and add add basic page info $requestArray = array(); $requests = $CI->uri->segment_array(); foreach ($requests as $request) { $pos = strrpos($request, ':'); if($pos >0) { list($key,$value)=explode(":", $request); if(!empty($value) || $value=’’) $requestArray[$key]=$value; } } return $requestArray ; }
Your url can be in the notation www.yoursite.com/index.php/class/function/request1:value1/request2:value2
To get the values from your request $request=getRequests(); echo $request['request1']; echo $request['request2'];
This function simply loops through the uri segements and picks up only elements with the nation request:value and returns the request array