Backend routing

Contents...

In the current framework version, the routing of HTTP requests to the application backend is not configurable and works according to fixed rules (which can, however, be overridden inside an individual application).

The common backend of all applications is accessible within address space http://{DOMAIN_NAME}/{PATH_TO_FRAMEWORK}/webasyst/*. The backend of each application is accessible within address space http://{DOMAIN_NAME}/{PATH_TO_FRAMEWORK}/webasyst/{APP_ID}/*, where APP_ID is the application identifier.

Relationship between the request URL and the class and method called for its processing is defined by the front controller class. By default (if an application does not have its own front controller) system class waFrontController is used, which works in accordance with the rules detailed below.

System front controller operating logic

Application backend is accessible via URLs of the form /webasyst/{APP_ID}/[?module=MODULE][&action=ACTION][&EXTRA_PARAMETERS]. System front controller waFrontController executes a specific module and an action of the requested application based on the values of parameters module and action retrieved from the GET request. Both parameters (module and action) are optional; if they are not specified, default class and method selection rules are applied. The default value for parameter module is backend. System front controller waFrontController searches a class and a method according to the rules described in section "Naming rules and recommendations".

Examples of relationship between request URLs and module methods

Below are shown examples of the module/method search algorithm operation for a sample application with identifier myblog:

/webasyst/myblog/

  1. myblogBackendController->execute()
  2. myblogBackendActions->defautAction()
  3. myblogBackendAction->execute()

/webasyst/myblog/?module=mail

  1. myblogMailController->execute()
  2. myblogMailActions->defautAction()
  3. myblogMailAction->execute()

/webasyst/myblog/?module=mail&action=test

  1. myblogMailTestController->execute()
  2. myblogMailActions->testAction()
  3. myblogMailTestAction->execute()

The system searches for a class and a method in the order shown above and executes the first found variant.

Overriding backend routing rules

If the routing rules of your application backend require modification of the default routing logic, you need to override the front controller for your application. To do so, create a new class extending base class waFrontController. Implement the request routing logic in its method dispatch.

Then add the following line to file wa-apps/{APP_ID}/lib/config/factories.php:

'front_controller' => 'YOUR_NAME_CLASS'

For example, if your application's front controller class name is myblogFrontController, then file factories.php should have the following contents:

<?php

return array(
    ...
    'front_controller' => 'myblogFrontController',
);