Created
May 30, 2011 22:22
-
-
Save dragoonis/999574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @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