Welcome Guest, Not a member yet? Register   Sign In
Passing an array through GET while using url_to_assoc
#8

[eluser]jhyland[/eluser]
This works. I modified the URI.php file.

Code:
function _uri_to_assoc($n = 3, $default = array(), $which = 'segment')
{
  if ($which == 'segment')
  {
   $total_segments = 'total_segments';
   $segment_array = 'segment_array';
  }
  else
  {
   $total_segments = 'total_rsegments';
   $segment_array = 'rsegment_array';
  }

  if ( ! is_numeric($n))
  {
   return $default;
  }

  if (isset($this->keyval[$n]))
  {
   return $this->keyval[$n];
  }

  if ($this->$total_segments() < $n)
  {
   if (count($default) == 0)
   {
    return array();
   }

   $retval = array();
   foreach ($default as $val)
   {
    $retval[$val] = FALSE;
   }
   return $retval;
  }

  $segments = array_slice($this->$segment_array(), ($n - 1));

  $var = array_chunk($segments, 2);

  $result = array();
  foreach ($var as $eachSet) {
   if (isset($eachSet[0]) and isset($eachSet[1])) {
    if (isset($result[$eachSet[0]])) {
     if (is_array($result[$eachSet[0]])) {
      $result[$eachSet[0]][] = $eachSet[1];
     } else {
      $result[$eachSet[0]] = array($result[$eachSet[0]]);
      $result[$eachSet[0]][] = $eachSet[1];
     }
    } else {
     $result[$eachSet[0]] = $eachSet[1];
    }
   }
  }

  // Cache the array for reuse
  $this->keyval[$n] = $result;
  return $result;
}

The request: http://localhost/index.php/ci/view_asset.../test/true

Returns:
Quote:Array
(
[foo] => Array
(
[0] => a
[1] => c
)

[bar] => Array
(
[0] => b
[1] => d
)

[test] => true
)

Hope this helps other people


Messages In This Thread
Passing an array through GET while using url_to_assoc - by El Forum - 08-07-2012, 01:25 AM
Passing an array through GET while using url_to_assoc - by El Forum - 08-07-2012, 03:28 AM
Passing an array through GET while using url_to_assoc - by El Forum - 08-07-2012, 11:04 AM
Passing an array through GET while using url_to_assoc - by El Forum - 08-07-2012, 11:29 AM
Passing an array through GET while using url_to_assoc - by El Forum - 08-09-2012, 02:01 PM
Passing an array through GET while using url_to_assoc - by El Forum - 08-09-2012, 03:22 PM
Passing an array through GET while using url_to_assoc - by El Forum - 08-09-2012, 04:28 PM
Passing an array through GET while using url_to_assoc - by El Forum - 08-09-2012, 05:53 PM
Passing an array through GET while using url_to_assoc - by El Forum - 08-10-2012, 06:35 PM
Passing an array through GET while using url_to_assoc - by El Forum - 08-19-2012, 07:58 PM



Theme © iAndrew 2016 - Forum software by © MyBB