This content may be out-of-date

This book was written circa 2022, when Joomla 4 was still a new thing. It has not been updated for Joomla 5 and beyond, and it's no longer being worked on. You can usually find more up-to-date information in the official Joomla! Manual.

Dispatching the component

The dispatcher object has a dispatch() method. This method looks in the request data to figure out which controller it needs to instantiate and which task it should execute on it. The controller object is instantiated through your component's MVCFactory service and its execute and redirect methods are called on it. So, yes, this is basically what your old Joomla 3 MVC controller.php file was doing.

[Tip]Tip

Having a custom dispatcher means that you can manipulate the controller and task based on other request variables.

This is very important when your component is accessed outside of a Joomla menu item (no Itemid in the request variables). In this case Joomla always uses the default (Home) menu item for the current language. This means that you may be getting a controller, view or task request variable — as well as other variables which might mess with your component, like id — from the Home menu item.

Your Dispatcher is responsible for figuring out if this is the case and fix the input variables to prevent weird bugs / showing the wrong page of your component when it's accessed without a menu item id, e.g. a URL like /component/example?view=foobar. This is something which has happened a lot when I converted my own extensions to Joomla 4, including LoginGuard (the extension contributed as Joomla's Multi-factor Authentication feature in Joomla 4.2).