JURI/base: Difference between revisions
From Joomla! Documentation
m removing red link to edit, no existant pages |
m preparing for archive only |
||
| Line 72: | Line 72: | ||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=base | category=base | ||
category=JURI | category=JURI | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
Latest revision as of 01:13, 25 March 2017
Description
Returns the base URI for the request.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
base($pathonly=false)
| Parameter Name | Default Value | Description |
|---|---|---|
| $pathonly | false | $pathonly If false, prepend the scheme, host and port information. Default is false. |
Returns
string The base URI string
Defined in
libraries/joomla/environment/uri.php
Importing
jimport( 'joomla.environment.uri' );
Source Body
function base($pathonly = false)
{
static $base;
// Get the base request path
if (!isset($base))
{
$config =& JFactory::getConfig();
$live_site = $config->getValue('config.live_site');
if(trim($live_site) != '') {
$uri =& JURI::getInstance($live_site);
$base['prefix'] = $uri->toString( array('scheme', 'host', 'port'));
$base['path'] = rtrim($uri->toString( array('path')), '/\\');
if(JPATH_BASE == JPATH_ADMINISTRATOR) {
$base['path'] .= '/administrator';
}
} else {
$uri =& JURI::getInstance();
$base['prefix'] = $uri->toString( array('scheme', 'host', 'port'));
if (strpos(php_sapi_name(), 'cgi') !== false && !empty($_SERVER['REQUEST_URI'])) {
//Apache CGI
$base['path'] = rtrim(dirname(str_replace(array('"', '<', '>', "'"), '', $_SERVER["PHP_SELF"])), '/\\');
} else {
//Others
$base['path'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
}
}
}
return $pathonly === false ? $base['prefix'].$base['path'].'/' : $base['path'];
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples