Joomla! Programmierung/Framework/JURI/getInstance

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

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] )
  • @return object Ein JURI Objekt.
  • @since Joomla 1.5
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

[Bearbeiten] Quellcode

JURI::getInstance in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • Folder green.png environment
      • File php.png uri.php
  1. public static function getInstance($uri = 'SERVER')
  2. {
  3.  
  4. if (empty(self::$instances[$uri]))
  5. {
  6. // Are we obtaining the URI from the server?
  7. if ($uri == 'SERVER')
  8. {
  9. // Determine if the request was over SSL (HTTPS).
  10. if (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off'))
  11. {
  12. $https = 's://';
  13. }
  14. else
  15. {
  16. $https = '://';
  17. }
  18.  
  19. // Since we are assigning the URI from the server variables, we first need
  20. // to determine if we are running on apache or IIS. If PHP_SELF and REQUEST_URI
  21. // are present, we will assume we are running on apache.
  22.  
  23. if (!empty($_SERVER['PHP_SELF']) && !empty($_SERVER['REQUEST_URI']))
  24. {
  25. // To build the entire URI we need to prepend the protocol, and the http host
  26. // to the URI string.
  27. $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  28. }
  29. else
  30. {
  31. // Since we do not have REQUEST_URI to work with, we will assume we are
  32. // running on IIS and will therefore need to work some magic with the SCRIPT_NAME and
  33. // QUERY_STRING environment variables.
  34.  
  35. // IIS uses the SCRIPT_NAME variable instead of a REQUEST_URI variable... thanks, MS
  36. $theURI = 'http' . $https . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'];
  37.  
  38. // If the query string exists append it to the URI string
  39. if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING']))
  40. {
  41. $theURI .= '?' . $_SERVER['QUERY_STRING'];
  42. }
  43. }
  44. }
  45. else
  46. {
  47. // We were given a URI
  48. $theURI = $uri;
  49. }
  50.  
  51. // Create the new JURI instance
  52. self::$instances[$uri] = new JURI($theURI);
  53. }
  54. return self::$instances[$uri];
  55. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge