_app classes

Doorkeeper apps are often user-developed extensions, but may also include build-in CMS features.

531 views

Edited: 2021-03-07 18:55

An app is usually a user-developed extension class that is called by the CMS when a pre-defined URL (Aka. route) is requested by a client.

Apps should be written as extensions to abstract_app_base.php in subdirectories of the _app directory; apps may also employ their own abstract_[APP_NAME]_base.php, which related classes need to extend.

Apps must at least include a main() method, and should call exit(); or send a response using the relevant methods. I.e.:

$tpl_content['content'] = '<p>Hallo World</p>';
$this->G->respond(
  template_content:$tpl_content + $this->c->get_content(),
  template_file: 'general_template.php');

It is not nessecery to include a template file, since the default template file will be used when none is provided.

If an app does not exit properly, an exception will be thrown.

Location

Apps are currently located in /lib/_app.

Routes

A request path can never be empty; according to the HTTP specification, a client should always at least include a forward slash / as the path. If the CMS receives a HTTP request with an empty path, an error is returned.

If a path corresponds with a pre-defined route, the linked app-code will be called.

Routes can currently be defined either as regular expressions or as strings in the routes.php class file.

Example route:

$this->article_view = new route(
  '/^\/[^\/\.]+$/', // The string or RegEx that the URL must match
  'articles\show_article', // The extension class that handles the route
  ['GET', 'HEAD'], // Allowed request methods
  ['fbclid'], // Allowed GET parameters
  null, // Allowed POST parameters
  false, // Include route in Sitemap
  null, // name
  'regex_route' // The route-type
);

Tell us what you think: