Uri Class
The Uri class allows you to interact with the URI.
base($include_index = true)
The base method return the base URL, excluding the index_file when $include_index
is set to false.
Please note: $include_index will be ignored if index_file is not set app/config/config.php
| Static |
Yes |
| Parameters |
| Param |
Default |
Description |
| $include_index |
true
|
Wether to append the index to the returned url. |
|
| Returns |
string, the base url with optional index file appended |
| Example |
echo Uri::base();
// http://localhost/index.php
echo Uri::base(false);
// http://localhost/
|
create($uri = null, $variables = array(), $get_variables = array())
The create method allows you to create a URL with the given URI, including the base URL.
| Static |
Yes |
| Parameters |
| Param |
Default |
Description |
| $uri |
null
|
The URL. |
| $variables |
array()
|
The variables for the URL. |
| $get_variables |
array()
|
The query string additions to the URL, its values & keys can use variables from
the $variables array. |
|
| Returns |
string |
| Example |
echo Uri::create('controller/method');
// returns http://localhost/controller/method
echo Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// returns http://localhost/controller/thing?what=more
echo Uri::create('http://www.example.org/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
// returns http://www.example.org/thing?what=more
|
current()
The current method allows you to fetch the current URL, including the base URL inside HMVC pattern.
| Static |
Yes |
| Parameters |
None |
| Returns |
string |
| Example |
// Example URL: http://localhost/module/controller/method
echo Uri::current(); // returns http://localhost/module/controller/method
|
main()
The main method allows you to fetch the current URL, including the base URL.
| Static |
Yes |
| Parameters |
None |
| Returns |
string |
| Example |
// Example URL: http://localhost/controller/method
echo Uri::main(); // returns http://localhost/controller/method
|
segment($segment, $default = null)
The segment method allows you to return the desired segment, or false if it does not exist.
| Static |
Yes |
| Parameters |
| Param |
Default |
Description |
| $segment |
Required |
The segment number. |
| $default |
null
|
The default? |
|
| Returns |
string |
| Example |
// Example URL: http://localhost/controller/method/param1/param2
echo Uri::segment(3); // returns param1
|
segments()
The segments method allows you to fetch the current URI segments in an array.
| Static |
Yes |
| Parameters |
None |
| Returns |
array |
| Example |
// Example URL: http://localhost/controller/method
echo Uri::segments(); // returns array(0 => 'controller', 1 => 'method')
|
to_assoc()
The to_assoc method takes the segments array and turns it into an associative array if the number of segments is even. If the number of segments is odd, it returns null.
| Static |
Yes |
| Parameters |
None |
| Returns |
array|null |
| Example |
// Uri is /welcome/index/page/4
$arr = Uri::to_assoc();
/*
Result:
array(
'welcome' => 'index',
'page' => 4,
);
*/
// Uri is /welcome
$arr = Uri::to_assoc();
/*
Result:
null
*/
|
string()
The string method allows you to fetch the current URI.
| Static |
Yes |
| Parameters |
None |
| Returns |
string |
| Example |
// Example URL: http://localhost/controller/method
echo Uri::string(); // returns controller/method
|