Dies ist eine alte Version des Dokuments!
Joomla - Router
Wie erstelle ich einen Router für die eigene Komponente?
Das Routing ersetzt die „normalen“ URLs (/index.php?option=com_content&view=article&id=1&Itemid=474) durch „lesbare“ URLs (/index.php/joomlabeitrag), indem alias Bezeichnungen eingesetzt werden. Dies geschieht durch das File router.php im root-Verzeichnis der jeweiligen Komponente.
In Joomla existieren zwei Ansätze, wie ein Router aufgebaut werden kann. Zum einen gibt es den neuen View-Based Router, welcher das Verhalten der Joomla-Core Komponenten nachzustellen vermag. Zum anderen gibt es den alten Custom-Router, mit welchem man jedes beliebige Verhalten bauen kann.
Weitere Infos: https://www.techfry.com/joomla/how-to-create-router-for-joomla-component
Neuer Router (View-Based)
Seit Joomla 3.8 gibt es eine neue Router-Klasse, die das Routing von Joomla vereinfachen soll, in dem es Methoden zu einem einfachen ansichtsbasierten (http://www.example.com/[menuitem]/[category]/[article]) Routing liefert.
Weitere Infos: https://groups.google.com/g/joomla-dev-general/c/YnILNx_Lmeg
- router.php
<?php public function __construct($app = null, $menu = null) { // If your view takes a URL identifier, like the &id= parameter of the // article view of com_content, you have to set the name of that identifier // variable in your $view object with $view->setKey(). $category = new RouterViewConfiguration('category'); $category->setKey('id')->setNestable(); $this->registerView($category); // If your view also has a parent view, like an article view which can // be reached via a category view, you then have to define the parent view // of $view. $article = new RouterViewConfiguration('article'); $article->setKey('id')->setParent($category, 'catid'); $this->registerView($article); parent::__construct($app, $menu); // implements the Itemid lookup for your router $this->attachRule(new MenuRules($this)); // implements the current behavior of the Joomla core components $this->attachRule(new StandardRules($this)); // implements the behavior when no Itemid is present after the Itemid lookup $this->attachRule(new NomenuRules($this)); }