API15

JURI/base

From Joomla! Documentation

< API15:JURI

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Returns the base URI for the request.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

base($pathonly=false)
Parameter Name Default Value Description
$pathonly false $pathonly If false, prepend the scheme, host and port information. Default is false.

Returns[edit]

string The base URI string

Defined in[edit]

libraries/joomla/environment/uri.php

Importing[edit]

jimport( 'joomla.environment.uri' );

Source Body[edit]

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[edit]

Code Examples[edit]