Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

The runtime context is state, that is calculated once per page, which affects:

  • URL generation logic for given TPL file
  • location of TPL files used to display page content for given URL

Known runtime contexts are:

Runtime ContextSetting NameConfigured From
Front-EndIs Front-End?/index.php
Theme NameURL
Mod-Rewrite UrlsSystem Setting
Admin ConsoleIs Admin Console?/admin/index.php

Typical URL examples:

URLWhere
http://www.website.tld/index.php?env=-platform%2Flogin%2Fregister%3Am0-1-1-1-s-
to the "platform/login/register" template in "advanced" theme on Front-End when Mod-Rewrite is disabled
http://www.website.tld/platform/login/register.html
to the "platform/login/register" template in "advanced" theme on Front-End when Mod-Rewrite is enabled
http://www.website.tld/admin/index.php?env=-languages%2Fphrase_list%3Am0--1--r-
to the "languages/phrase_list" template in Admin Console

If a need arises to build url to Admin Console from Front-End or vice versa then this can be done, to the certain extent, using this code:

While in Admin Console Only
// URL to Front-End page:
$url = $this->Application->HREF(
	'path/to/template',
	'_FRONT_END_', // To remove "/admin" from URL.
	array('__MOD_REWRITE__' => 1) // Mod-rewrite not used in Admin Console, so needs to be specified.
);
 
// Path to Front-End template from "advanced" theme:
$this->Application->InitParser('advanced');
$path1 = $this->Application->TemplatesCache->GetRealFilename('path/to/template1');
$path2 = $this->Application->TemplatesCache->GetRealFilename('path/to/template2');
 
// Path to Front-End template from given theme:
$this->Application->InitParser(true);
$path1 = $this->Application->TemplatesCache->GetRealFilename('theme:advanced/path/to/template1');
$path2 = $this->Application->TemplatesCache->GetRealFilename('theme:simple/path/to/template2');

Above examples demonstrate, that:

  • it's hard to use because the need of deep system understanding
  • some stuff needs be hardcoded for it to work

It can't be seen from code, but there are couple of other issues with it:

  • works only when building Front-End url from Admin Console, but not other way around
  • the built URL in edge cases will different from same URLs built on Front-End directly (e.g. impossible to built url using "use_section" parameter)

Solution

Allow to replace all variables (e.g. runtime context) that are imposed by the way how page was opened at once.

// Use Admin context.
$backup = $this->Application->applyRuntimeContext(new AdminRuntimeContext());
// do something
$this->Application->applyRuntimeContext($backup);
 
// Use Front-End context from current theme.
$backup = $this->Application->applyRuntimeContext(new FrontEndRuntimeContext());
// do something
$this->Application->applyRuntimeContext($backup);
 
// Use Front-End context from primary theme.
$backup = $this->Application->applyRuntimeContext(new FrontEndRuntimeContext('default'));
// do something
$this->Application->applyRuntimeContext($backup);

// Use Front-End context from given theme.
$backup = $this->Application->applyRuntimeContext(new FrontEndRuntimeContext(5));
// do something
$this->Application->applyRuntimeContext($backup);

Related Tasks

  • No labels