| | 71 | |
| | 72 | /** |
| | 73 | * Method: argument |
| | 74 | * Retrieve a specific URI argument. This is the part of the segments that does not indicate controller |
| | 75 | * or method |
| | 76 | * |
| | 77 | * Parameters: |
| | 78 | * index - argument number or label |
| | 79 | * default - default value returned if segment does not exist |
| | 80 | * |
| | 81 | * Returns: |
| | 82 | * Value of segment |
| | 83 | */ |
| | 84 | public function argument($index = 1, $default = FALSE) |
| | 85 | { |
| | 86 | if (is_string($index)) |
| | 87 | { |
| | 88 | if (($key = array_search($index, self::$arguments)) === FALSE) |
| | 89 | return $default; |
| | 90 | |
| | 91 | $index = $key + 2; |
| | 92 | } |
| | 93 | |
| | 94 | $index = (int) $index - 1; |
| | 95 | |
| | 96 | return isset(self::$arguments[$index]) ? self::$arguments[$index] : $default; |
| | 97 | } |
| 131 | | |
| | 158 | |
| | 159 | /** |
| | 160 | * Method: argument_array |
| | 161 | * Returns an array containing all the URI arguments. |
| | 162 | * |
| | 163 | * Parameters: |
| | 164 | * offset - segment offset |
| | 165 | * associative - return an associative array |
| | 166 | * |
| | 167 | * Returns: |
| | 168 | * Array of URI segment arguments |
| | 169 | */ |
| | 170 | public function argument_array($offset = 0, $associative = FALSE) |
| | 171 | { |
| | 172 | $argument_array = self::$arguments; |
| | 173 | array_unshift($argument_array, 0); |
| | 174 | $argument_array = array_slice($argument_array, $offset + 1, $this->total_arguments(), TRUE); |
| | 175 | |
| | 176 | if ( ! $associative) |
| | 177 | return $argument_array; |
| | 178 | |
| | 179 | $argument_array_assoc = array(); |
| | 180 | |
| | 181 | foreach (array_chunk($argument_array, 2) as $pair) |
| | 182 | { |
| | 183 | $argument_array_assoc[$pair[0]] = isset($pair[1]) ? $pair[1] : ''; |
| | 184 | } |
| | 185 | |
| | 186 | return $argument_array_assoc; |
| | 187 | } |
| | 188 | |