JRoute/

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

Konvertiert einen normalen Joomla! Link zu einem SEO Link

Inhaltsverzeichnis

[Bearbeiten] Syntax

public static function _($url, [$xhtml = true], [$ssl = null])
  • @return string Der konvertierte Link
  • @since Joomla 11.1
Datentyp Parameter Beschreibung
string $url Absoluter oder relativer Joomla! Link.
boolean [$xhtml = true] Ersetzt & mit & für XHTML Kompatibilität.
integer [$ssl = null] Erzeugt je nach Parameter eine sichere Verbindung:
  • -1 => http:// wird genutzt
  • 0 => die übergebene Verbindung wird genutzt
  • 1 => https:// wird genutzt.

[Bearbeiten] Beispiele

echo JRoute::_('index.php?option=com_content&id=32-joomla-nafu&Itemid=5');

Die Ausgabe kann sehr variieren, je nach Verlinkung und Position im Menu. Es könnte ähnlich wie hier aussehen:

http://www.joomla.org/texte/32-joomla-nafu.html

[Bearbeiten] Quellcode

JRoute::_ in Joomla! 2.5.4

Folder blue.png libraries

  • Folder red.png joomla
    • File php.png methods.php
  1. public static function _($url, $xhtml = true, $ssl = null)
  2. {
  3. // Get the router.
  4. $app = JFactory::getApplication();
  5. $router = $app->getRouter();
  6.  
  7. // Make sure that we have our router
  8. if (!$router)
  9. {
  10. return null;
  11. }
  12.  
  13. if ((strpos($url, '&') !== 0) && (strpos($url, 'index.php') !== 0))
  14. {
  15. return $url;
  16. }
  17.  
  18. // Build route.
  19. $uri = $router->build($url);
  20. $url = $uri->toString(array('path', 'query', 'fragment'));
  21.  
  22. // Replace spaces.
  23. $url = preg_replace('/\s/u', '%20', $url);
  24.  
  25. /*
  26.   * Get the secure/unsecure URLs.
  27.   *
  28.   * If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
  29.   * https and need to set our secure URL to the current request URL, if not, and the scheme is
  30.   * 'http', then we need to do a quick string manipulation to switch schemes.
  31.   */
  32. if ((int) $ssl)
  33. {
  34. $uri = JURI::getInstance();
  35.  
  36. // Get additional parts.
  37. static $prefix;
  38. if (!$prefix)
  39. {
  40. $prefix = $uri->toString(array('host', 'port'));
  41. }
  42.  
  43. // Determine which scheme we want.
  44. $scheme = ((int) $ssl === 1) ? 'https' : 'http';
  45.  
  46. // Make sure our URL path begins with a slash.
  47. if (!preg_match('#^/#', $url))
  48. {
  49. $url = '/' . $url;
  50. }
  51.  
  52. // Build the URL.
  53. $url = $scheme . '://' . $prefix . $url;
  54. }
  55.  
  56. if ($xhtml)
  57. {
  58. $url = htmlspecialchars($url);
  59. }
  60.  
  61. return $url;
  62. }

[Bearbeiten] Siehe auch

Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge