Class CI_URI - echiong/testRepo GitHub Wiki

##Class CI_URI

URI Class

Parses URIs and determines routing

Package: [[CodeIgniter<a href="Package CodeIgniter.Libraries.md">Libraries]]
Category: URI
Author: ExpressionEngine Dev Team
Link: http://codeigniter.com/user_guide/libraries/uri.html
Located at system/core/URI.php

##Methods summary


public __construct ( )

Constructor

Simply globalizes the $RTR object. The front loads the Router class early on so it's not available normally as other classes are.


public string _fetch_uri_string ( )

Get the URI String

Returns string


public string _set_uri_string ( string $str )

Set the URI String

Parameters

$str string

Returns string


public string _filter_uri ( string $str )

Filter segments for malicious characters

Parameters

$str string

Returns string


public _remove_url_suffix ( )

Remove the suffix from the URL if needed


public _explode_segments ( )

Explode the URI Segments. The individual segments will be stored in the $this->segments array.


public _reindex_segments ( )

Re-index Segments

This function re-indexes the $this->segment array so that it starts at 1 rather than 0. Doing so makes it simpler to use functions like $this->uri->segment(n) since there is a 1:1 relationship between the segment array and the actual segments.


public string segment ( integer $n, boolean $no_result = FALSE )

Fetch a URI Segment

This function returns the URI segment based on the number provided.

Parameters

$n integer

$no_result boolean

Returns string


public string rsegment ( integer $n, boolean $no_result = FALSE )

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()

Parameters

$n integer

$no_result boolean

Returns string


public array uri_to_assoc ( integer $n = 3, array $default = array() )

Generate a key value pair from the URI string

This function generates and associative array of URI data starting at the supplied segment. For example, if this is your URI:

example.com/user/search/name/joe/location/UK/gender/male

You can use this function to generate an array with this prototype:

array ( name => joe location => UK gender => male )

Parameters

$n integer
the starting segment number

$default array
an array of default values

Returns array


public array ruri_to_assoc ( integer $n = 3, array $default = array() )

Identical to above only it uses the re-routed segment array

Parameters

$n integer
the starting segment number

$default array
an array of default values

Returns array


public array _uri_to_assoc ( integer $n = 3, array $default = array(), string $which = 'segment' )

Generate a key value pair from the URI string or Re-routed URI string

Parameters

$n integer
the starting segment number

$default array
an array of default values

$which string
which array we should use

Returns array


public array assoc_to_uri ( array $array )

Generate a URI string from an associative array

Parameters

$array array
an associative array of key/values

Returns array


public string slash_segment ( integer $n, string $where = 'trailing' )

Fetch a URI Segment and add a trailing slash

Parameters

$n integer

$where string

Returns string


public string slash_rsegment ( integer $n, string $where = 'trailing' )

Fetch a URI Segment and add a trailing slash

Parameters

$n integer

$where string

Returns string


public string _slash_segment ( integer $n, string $where = 'trailing', string $which = 'segment' )

Fetch a URI Segment and add a trailing slash - helper function

Parameters

$n integer

$where string

$which string

Returns string


public array segment_array ( )

Segment Array

Returns array


public array rsegment_array ( )

Routed Segment Array

Returns array


public integer total_segments ( )

Total number of segments

Returns integer


public integer total_rsegments ( )

Total number of routed segments

Returns integer


public string uri_string ( )

Fetch the entire URI string

Returns string


public string ruri_string ( )

Fetch the entire Re-routed URI string

Returns string

<table class="summary" id="properties">
<caption>Properties summary</caption>
<tr data-order="keyval" id="$keyval">
	<td class="attributes"><code>
		public  
		array
	</code></td>

	<td class="name">

$keyval

array()
#
		<div class="description detailed">

List of cached uri segments

		</div>
	</div></td>
</tr>
<tr data-order="uri_string" id="$uri_string">
	<td class="attributes"><code>
		public  
		string
	</code></td>

	<td class="name">

$uri_string

#
		<div class="description detailed">

Current uri string

		</div>
	</div></td>
</tr>
<tr data-order="segments" id="$segments">
	<td class="attributes"><code>
		public  
		array
	</code></td>

	<td class="name">

$segments

array()
#
		<div class="description detailed">

List of uri segments

		</div>
	</div></td>
</tr>
<tr data-order="rsegments" id="$rsegments">
	<td class="attributes"><code>
		public  
		array
	</code></td>

	<td class="name">

$rsegments

array()
#
		<div class="description detailed">

Re-indexed list of uri segments Starts at 1 instead of 0

		</div>
	</div></td>
</tr>
</table>
⚠️ **GitHub.com Fallback** ⚠️