Skip to content

The Dispatcher

Eduardo Diaz edited this page Jul 25, 2016 · 5 revisions

The Dispatcher is what handles the request on behalf of your component (be it a web request or an HMVC request). Its job is to decide which controller to create and which task to run. Further to that it works with the TransparentAuthentication object to handle transparent authentication which comes in really handy if you want to perform remote requests to your component, interacting with access-restricted data or actions (viewing items protected behind a login, performing privileged operations such as creating / editing / deleting records and so on).

Class and file naming conventions

The class is called Dispatcher and it's placed inside the Dispatcher namespace of your component. For example:


namespace Acme\MyComponent\Site\Dispatcher;

class Dispatcher extends \FOF30\Dispatcher\Dispatcher

The file must be called Dispatcher.php and placed inside your component's Dispatcher directory for FOF's PSR-4 autoloader to find it.

If the Dispatcher class cannot be found FOF will fall back to creating a suitably configured instance of \FOF30\Dispatcher\Dispatcher, using convention over configuration to determine what the Dispatcher object should do.

Customising a specialised class

Unlike plain old Joomla! you are NOT supposed to copy and paste code when dealing with FOF. Our rule of thumb is that if you ever find yourself copying code from Dispatcher into your extension's specialised table class you're doing it wrong.

FOF dispatcher can be customised very easily using the onBeforeDispatch / onAfterDispatch methods. onBeforeDispatch runs before the dispatcher executes and onAfterDispatch runs right after the dispatcher executes. Throwing an exception will result in a 403 Forbidden error.

Please note that when your component is running under CLI it will use the onBeforeDispatchCLI and onAfterDispatchCLI methods.

Clone this wiki locally
You can’t perform that action at this time.