Changeset 2654

Show
Ignore:
Timestamp:
05/07/08 11:46:44 (2 months ago)
Author:
Shadowhand
Message:

Added url::merge() (badly needs a new name, and possibly better functionality)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/system/helpers/url.php

    r2644 r2654  
    1313 
    1414        /** 
     15         * Fetches the current URI. 
     16         * 
     17         * @param   boolean  include the query string 
     18         * @return  string 
     19         */ 
     20        public static function current($qs = FALSE) 
     21        { 
     22                return Router::$current_uri.($qs === TRUE ? Router::$query_string : ''); 
     23        } 
     24 
     25        /** 
    1526         * Base URL, with or without the index page. 
    1627         * 
     
    102113 
    103114        /** 
    104          * Fetches the current URI. 
    105          * 
    106          * @param   boolean  include the query string 
    107          * @return  string 
    108          */ 
    109         public static function current($qs = FALSE) 
    110         { 
    111                 return Router::$current_uri.($qs === TRUE ? Router::$query_string : ''); 
     115         * Merges an array of arguments with the current URI and query string to 
     116         * overload, instead of replace, the current query string. 
     117         * 
     118         * @param   array   associative array of arguments 
     119         * @return  string 
     120         */ 
     121        public static function merge(array $arguments) 
     122        { 
     123                if ($_GET === $arguments) 
     124                { 
     125                        $query = Router::$query_string; 
     126                } 
     127                elseif ($query = http_build_query(array_merge($_GET, $arguments))) 
     128                { 
     129                        $query = '?'.$query; 
     130                } 
     131 
     132                // Return the current URI with the arguments merged into the query string 
     133                return Router::$current_uri.$query; 
    112134        } 
    113135