Select your language

JoomGallery allows you to add your custom routers. Here you can learn how to do this.

The basic Principle

In general, JoomGallery lists in its configuration all PHP files/routers that are located in the directory site\com_joomgallery\src\Service and contain Router in their name. To add a custom router, you therefore need to add a PHP file that contains a router class.

  • To create a modern router, the router class must extend Joomla\CMS\Component\Router\RouterView.
  • For a legacy router, the router class must implement Joomla\CMS\Component\Router\RouterInterface.

The property $displayName is the display name of the router as it appears in the dropdown list in the configuration.

Take also a look into the general documentation of modern Routers:

Modern Router

A Modern Router

Creating a modern router is quite straightforward and effective. This is the template for a new router:

class CustomRouter extends DefaultRouter {
 public static string $displayName = 'Custom Router';
 public static string $image_parentID = 'catid';

 public function __construct($app, $menu, $categoryFactory, $db) {
  parent::__construct($app, $menu, $categoryFactory, $db, true);
  // ... here come your custom RouterView definitions
 }
}


In the constructor of the router class, alternative RouterViews can then be defined. For example, it can be specified that the URL of the detail view is generated directly as a child of the gallery view.

/gallery/1-flugzeug.html

This example requires the following RouterViews definitions:

 $gallery = new RouterViewConfiguration('gallery');
 $this->registerView($gallery);

 $image = new RouterViewConfiguration('image');
 $image->setKey('id')->setParent($gallery);
 $this->registerView($image);

 $this->attachRule(new MenuRules($this));
 $this->attachRule(new StandardRules($this));

Using this principle, completely custom URLs can be generated according to entirely custom logic.

Most often read articles

Donation

Donate to JoomGallery friends

Enter total:

Why donating helps

Apart from a lot of volunteery work for the development of our software the maintenance of this website costs real money.
Additionally the form has to be hosted and maintained.
Support the development of our JoomGallery project with a donation so that we can continue to provide most of our software free and ad-free.

We say THANK YOU for your support!

 

Sorry, this website uses features that your browser doesn't support. Upgrade to a newer version of Firefox, Chrome, Safari, or Edge and you'll be all set.