Piwik\

FrontController

This singleton dispatches requests to the appropriate plugin Controller.

Matomo (formerly Piwik) uses this class for all requests that go through index.php. Plugins can use it to call controller actions of other plugins.

Examples

Forwarding controller requests

public function myConfiguredRealtimeMap()
{
    $_GET['changeVisitAlpha'] = false;
    $_GET['removeOldVisits'] = false;
    $_GET['showFooterMessage'] = false;
    return FrontController::getInstance()->dispatch('UserCountryMap', 'realtimeMap');
}

Using other plugin controller actions

public function myPopupWithRealtimeMap()
{
    $_GET['changeVisitAlpha'] = false;
    $_GET['removeOldVisits'] = false;
    $_GET['showFooterMessage'] = false;
    $realtimeMap = FrontController::getInstance()->dispatch('UserCountryMap', 'realtimeMap');

    $view = new View('@MyPlugin/myPopupWithRealtimeMap.twig');
    $view->realtimeMap = $realtimeMap;
    return $realtimeMap->render();
}

For a detailed explanation, see the documentation here.

Methods

The class defines the following methods:

  • getInstance() ash; Returns the singleton instance for the derived class. Inherited from Singleton
  • dispatch() — Executes the requested plugin controller method.

getInstance()

Returns the singleton instance for the derived class.

If the singleton instance has not been created, this method will create it.

Signature

dispatch()

Executes the requested plugin controller method.

Signature

  • It accepts the following parameter(s):

    • $module (string) — The name of the plugin whose controller to execute, eg, 'UserCountryMap'.
    • $action (string) — The controller method name, eg, 'realtimeMap'.
    • $parameters (array) — Array of parameters to pass to the controller method.
  • Returns: void|mixed — The returned value of the call. This is the output of the controller method.

  • It throws one of the following exceptions:
    • Exception|\Piwik\Exception\PluginDeactivatedException — in case the plugin doesn't exist, the action doesn't exist, there is not enough permission, etc.