Show
Ignore:
Timestamp:
12/07/2007 03:04:05 PM (13 months ago)
Author:
Geert
Message:
  • Added uri->rsegment_array(), uri->total_rsegments() and uri->last_rsegment()
  • Synced i18n/nl_NL
  • Some other minor changes
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/URI.php

    r1230 r1449  
    126126 
    127127        /** 
     128         * Method: rsegment_array 
     129         *  Returns an array containing all the re-routed URI segments. 
     130         * 
     131         * Parameters: 
     132         *  offset      - rsegment offset 
     133         *  associative - return an associative array 
     134         * 
     135         * Returns: 
     136         *   Array of re-routed URI segments 
     137         */ 
     138        public function rsegment_array($offset = 0, $associative = FALSE) 
     139        { 
     140                $segment_array = self::$rsegments; 
     141                array_unshift($segment_array, 0); 
     142                $segment_array = array_slice($segment_array, $offset + 1, $this->total_segments(), TRUE); 
     143 
     144                if ( ! $associative) 
     145                        return $segment_array; 
     146 
     147                $segment_array_assoc = array(); 
     148 
     149                foreach (array_chunk($segment_array, 2) as $pair) 
     150                { 
     151                        $segment_array_assoc[$pair[0]] = isset($pair[1]) ? $pair[1] : ''; 
     152                } 
     153 
     154                return $segment_array_assoc; 
     155        } 
     156 
     157        /** 
    128158         * Method: string 
    129159         *  Returns the complete URI as a string. 
     
    136166                return self::$current_uri; 
    137167        } 
    138          
     168 
     169        /** 
     170         * Method: __toString 
     171         *  Magic method for converting an object to a string. 
     172         * 
     173         * Returns: 
     174         *  Full URI as string 
     175         */      
    139176        public function __toString() 
    140177        { 
     
    152189        { 
    153190                return count(self::$segments); 
     191        } 
     192 
     193        /** 
     194         * Method: total_rsegments 
     195         *  Returns the total number of re-routed URI segments. 
     196         * 
     197         * Returns: 
     198         *   Total number of re-routed URI segments 
     199         */ 
     200        public function total_rsegments() 
     201        { 
     202                return count(self::$rsegments); 
    154203        } 
    155204 
     
    169218        } 
    170219 
     220        /** 
     221         * Method: last_rsegment 
     222         *  Returns the last re-routed URI segment. 
     223         * 
     224         * Returns: 
     225         *   Last re-routed URI segment 
     226         */ 
     227        public function last_rsegment($default = FALSE) 
     228        { 
     229                if ($this->total_rsegments() < 1) 
     230                        return $default; 
     231                 
     232                return end(self::$rsegments); 
     233        } 
     234 
    171235} // End URI Class