-
Notifications
You must be signed in to change notification settings - Fork 7.6k
alternative to GET
By default CodeIgniter's $_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? Try this simple helper function.
Create a simple helper and call it request. Use this function: [code]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 ; } [/code] 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 [code]$request = getRequests(); echo $request['request1']; echo $request['request2'];[/code]
This function simply loops through the uri segements and picks up only elements with the nation request:value and returns the request array