GeniXCMS

BaseControl Class

categoryAPI edit_calendar31 Mar 2026

BaseControl Class


The BaseControl is an abstract class that serves as the foundation for all frontend and backend controller classes in GeniXCMS. It provides a standardized way to initialize the Latte templating engine, populate common global data, and render theme views.

priority_high
ImportantBecause this is an abstract class, it cannot be instantiated directly. All page controllers (e.g., FrontControl, AdminControl) must extend BaseControl.

Constructor

When a controller extends BaseControl, the constructor automatically performs two tasks:

  1. initLatte(): Sets up the Latte template engine instance, including language support and custom filters.
  2. initCommonData(): Populates the $this->data array with global variables available to every template.

Template Engine (Latte)

The initLatte() method configures the Latte engine with:

  • RawPhpExtension: Allows raw PHP execution in templates.
  • TranslatorExtension: Hooks into the Typo::translate() function for i18n support.
  • nl2br filter: Converts newlines to HTML <br> tags.
  • stripHtml filter: Strips HTML tags from a string.
  • Temp Directory: Compiled templates are cached in GX_CACHE/temp.

Common Data (initCommonData)

The following variables are automatically available in every Latte template:

Variable Source Description
$website_lang Options 2-letter language code
$site_name Site::$name The website's title
$site_url Site::$url The base URL
$site_cdn Site::$cdn CDN URL, if configured
$site_logo Site::logo() Pre-rendered logo HTML
$theme_url Url::theme() URL to the active theme folder
$token TOKEN CSRF token for forms
$tag_cloud Tags::cloud() Rendered tag cloud HTML
$archives_list Archives::list(10) Rendered archive links HTML
$platform_version System::v() The current CMS version string

Render Method

Usage: $this->render(string $view, array $data = []);

This is the core output method for any controller extending BaseControl. It:

  1. Merges controller-specific $data with the common data array.
  2. Generates SEO meta tags via Site::meta($this->data).
  3. Starts the Cache buffer.
  4. Renders the theme's header.php, then the specified $view.php, then footer.php using Latte.
  5. Ends the Cache buffer, storing the output if caching is enabled.
class FrontControl extends BaseControl
{
    public function index($data)
    {
        $data['p_type'] = 'index';
        $this->render('index', $data);
    }
}