Skip to content

Instantly share code, notes, and snippets.

@dragoonis
Created May 30, 2011 22:22
Show Gist options
  • Select an option

  • Save dragoonis/999574 to your computer and use it in GitHub Desktop.

Select an option

Save dragoonis/999574 to your computer and use it in GitHub Desktop.
/**
* @param string $var
* @param mixed $default
* @return mixed
*/
function get($var, $default = null) {
if(empty($this->_uriParams)) {
$this->processUriParams();
}
if(isset($_GET[$var])) {
return urldecode(is_numeric($var) ? (int) $var : $var);
}
return isset($this->_uriParams[$var]) ? $this->_uriParams[$var] : $default;
}
/**
* Process the URI Parameters into a clean hashmap for isset() calling later.
*
* @return void
*/
function processUriParams() {
$params = array();
$uriParams = explode('/', trim($this->_uri, '/'));
$count = count($uriParams);
if($count > 0) {
for($i = 0, $j = 1; $i < $count; $i++, $j++) {
$val = isset($uriParams[$j]) ? $uriParams[$j] : null;
$params[$uriParams[$i]] = urldecode(is_numeric($val) ? (int) $val : $val);
}
$this->_uriParams = $params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment