From daf454dabe983f621570bcef10d6d8babedfb8a8 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 21 Sep 2006 17:01:27 +0000 Subject: --- system/libraries/URI.php | 93 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 91 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/URI.php b/system/libraries/URI.php index ba6279e88..11562eb29 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -65,6 +65,25 @@ class CI_URI { // -------------------------------------------------------------------- + /** + * Fetch a URI "routed" Segment + * + * This function returns the re-routed URI segment (assuming routing rules are used) + * based on the number provided. If there is no routing this function returns the + * same result as $this->segment() + * + * @access public + * @param integer + * @param bool + * @return string + */ + function rsegment($n, $no_result = FALSE) + { + return ( ! isset($this->router->rsegments[$n])) ? $no_result : $this->router->rsegments[$n]; + } + + // -------------------------------------------------------------------- + /** * Generate a key value pair from the URI string * @@ -168,7 +187,6 @@ class CI_URI { return implode('/', $temp); } - // -------------------------------------------------------------------- /** @@ -180,6 +198,37 @@ class CI_URI { * @return string */ function slash_segment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'segment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash + * + * @access public + * @param integer + * @param string + * @return string + */ + function slash_rsegment($n, $where = 'trailing') + { + return $this->_slash_segment($n, $where, 'rsegment'); + } + + // -------------------------------------------------------------------- + + /** + * Fetch a URI Segment and add a trailing slash - helper function + * + * @access private + * @param integer + * @param string + * @param string + * @return string + */ + function _slash_segment($n, $where = 'trailing', $which = 'segment') { if ($where == 'trailing') { @@ -196,7 +245,7 @@ class CI_URI { $leading = '/'; $trailing = '/'; } - return ( ! isset($this->router->segments[$n])) ? '' : $leading.$this->router->segments[$n].$trailing; + return ( ! isset($this->router->$which[$n])) ? '' : $leading.$this->router->$which[$n].$trailing; } // -------------------------------------------------------------------- @@ -211,6 +260,19 @@ class CI_URI { { return $this->router->segments; } + + // -------------------------------------------------------------------- + + /** + * Routed Segment Array + * + * @access public + * @return array + */ + function rsegment_array() + { + return $this->router->rsegments; + } // -------------------------------------------------------------------- @@ -224,6 +286,19 @@ class CI_URI { { return count($this->router->segments); } + + // -------------------------------------------------------------------- + + /** + * Total number of routed segments + * + * @access public + * @return integer + */ + function total_rsegments() + { + return count($this->router->rsegments); + } // -------------------------------------------------------------------- @@ -238,6 +313,20 @@ class CI_URI { return $this->router->uri_string; } + + // -------------------------------------------------------------------- + + /** + * Fetch the entire Re-routed URI string + * + * @access public + * @return string + */ + function uri_rstring() + { + return '/'.implode('/', $this->rsegment_array()).'/'; + } + } // END URI Class ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b