Joomla! Programmierung/Framework/JURI/getInstance
Aus Joomla! Dokumentation
JURI/getInstance gibt entweder eine Referenz auf das globale JURI Object zurück, wobei es nur erstellt wird wenn es noch nicht existiert, oder erstellt ein neues Objekt welches die im Parameter übergebene URI darstellt.
Das globale URI Objekt beinhaltet die URI die zum erscheinen der aktuellen Seite geführt hat.
Inhaltsverzeichnis |
[Bearbeiten] Syntax
static getInstance( [$uri] )
| Parameter | Datentyp | Beschreibung | Standardwert |
|---|---|---|---|
| [$uri] | string | Die URI welche vom JURI Objekt dargestellt werden soll. Lautet der String SERVER wird die Request URI angenommen. | SERVER |
[Bearbeiten] Beispiel 1
In diesem Beispiel wird ein URI Objekt erstellt und zurück in einen String konvertiert.
$uri = 'http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis'; $u =& JURI::getInstance( $uri ); echo 'Die URI ist: '.$u->toString();
Ausgabe
Die URI ist: http://fredbloggs:itsasecret@www.example.com:8080/path/to/Joomla/index.php?task=view&id=32#anchorthis
[Bearbeiten] Beispiel 2
Um die aktuelle Request URI zu erhalten, kann diese Methode ohne Argumente aufgerufen werden. Dies ist gleichbedeutend mit einem Aufruf von JFactory::getURI().
$u =& JURI::getInstance(); echo 'Die Request URI ist: '.$u->toString();
Ausgabe
Die Request URI ist: http://localhost/joomla/index.php?option=com_content&view=article&id=1&Itemid=50
[Bearbeiten] Siehe auch
- JURI->getInstance() auf api.joomla.org
- JFactory::getURI()
[Bearbeiten] Quellcode
{ { // Are we obtaining the URI from the server? if ($uri == 'SERVER') { // Determine if the request was over SSL (HTTPS). if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) { $https = 's://'; } else { $https = '://'; } // Since we are assigning the URI from the server variables, we first need // to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI // are present, we will assume we are running on apache. { // To build the entire URI we need to prepend the protocol, and the http host // to the URI string. $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; } else { // Since we do not have REQUEST_URI to work with, we will assume we are // running on IIS and will therefore need to work some magic with the SCRIPT_NAME and // QUERY_STRING environment variables. // IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; // If the query string exists append it to the URI string { $theURI .= '?' . $_SERVER['QUERY_STRING']; } } } else { // We were given a URI $theURI = $uri; } // Create the new JURI instance } return self::$instances[$uri]; }