Joomla! Programmierung/Framework/JURI/root

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

ToDo JURI/root A static method that returns the root URI of the Joomla site. If Joomla has been installed in the web server's document root then this method will return "/" for the path.

Inhaltsverzeichnis

[Bearbeiten] Syntax

static root( [$pathonly], [$path] )
  • @return string The root URI string
  • @since 1.5
Parameter Datentyp Beschreibung Standardwert
[$pathonly] boolean If true then only the path to the Joomla site is returned; otherwise the scheme, host and port are prepended to the path. Note that when true the URI returned has a trailing "/", but when false the trailing "/" is omitted. false
$path string Path to override the actual path. Since this is held statically it will affect all subsequent calls to this method. null

[Bearbeiten] Beispiel

In this example, the Joomla root URI is shown with both values of the $pathonly argument. A new path is also applied and it should be noted that it affects subsequent calls to this method.

echo 'Joomla root URI is ' . JURI::root() . "\n";
echo 'Joomla root URI (path only) is ' . JURI::root( true ) . "\n";
echo 'Joomla root URI (path specified) is ' . JURI::root( false, '/a-different-path' ) . "\n";
echo 'Joomla root URI (path only) (path specified) is ' . JURI::root( true, '/a-different-path' ) . "\n";
echo "\n";
echo 'Joomla root URI is ' . JURI::root() . "\n";
echo 'Joomla root URI (path only) is ' . JURI::root( true ) . "\n";

might output

Joomla root URI is http://localhost/joomla15svn10812/
Joomla root URI (path only) is /joomla15svn10812
Joomla root URI (path specified) is http://localhost/a-different-path/
Joomla root URI (path only) (path specified) is /a-different-path

Joomla root URI is http://localhost/a-different-path/
Joomla root URI (path only) is /a-different-path

[Bearbeiten] Siehe auch

[Bearbeiten] Source code

JURI::root 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 root($pathonly = false, $path = null)
  2. {
  3. // Get the scheme
  4. if (empty(self::$root))
  5. {
  6. $uri = self::getInstance(self::base());
  7. self::$root['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
  8. self::$root['path'] = rtrim($uri->toString(array('path')), '/\\');
  9. }
  10.  
  11. // Get the scheme
  12. if (isset($path))
  13. {
  14. self::$root['path'] = $path;
  15. }
  16.  
  17. return $pathonly === false ? self::$root['prefix'] . self::$root['path'] . '/' : self::$root['path'];
  18. }
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge