Page Controller (pages.php)
Relevant source files
The following files were used as context for generating this wiki page:
The page controller system is a simple, file-based routing and rendering mechanism responsible for handling user requests, managing multi-language content, and assembling the final HTML pages. It uses individual PHP scripts as controllers for each page, a central PHP array in apps/pages.php for page title translations, and a master layout file to ensure a consistent structure across the site. This approach mimics a basic Model-View-Controller (MVC) pattern where the controller script fetches data (translations) and renders a view within a layout.
The core of this system is the convention over configuration pattern where each public-facing page (e.g., /iite/overview.php) has a corresponding PHP script that orchestrates the rendering process. This process involves session management for language preferences, loading translations, capturing page-specific content from a .phtml template using output buffering, and injecting it into a global layout.
Core Architecture
The architecture is based on a set of standalone PHP scripts that act as page controllers. When a user navigates to a URL like /iite/company.php, the web server executes this script directly. The script then follows a standardized sequence to build and return the HTML response.
Request Lifecycle
The following diagram illustrates the step-by-step process from the initial user request to the final rendered page.
This diagram shows the server-side rendering flow for a typical page request.
Sources: iite/overview.php, iite/company.php, index.php
Key Components
The system is composed of several distinct file types, each with a specific role.
| File/Component | Role | Example Source |
|---|---|---|
| Controller Scripts | Handle requests, manage session/language, load data, and orchestrate view rendering within the main layout. | iite/overview.php, login.php |
apps/pages.php | A PHP array acting as a dictionary for page titles, keyed by page identifier and language code. | apps/pages.php |
apps/translations.json | A JSON file containing all other UI text translations, used separately from page titles. | apps/translations.json |
View Scripts (.phtml) | Templates containing the unique HTML content for a specific page's body. | themes/apps/iite/overview.phtml |
Layout Script (layout.phtml) | The master template that includes the common site structure (header, footer, etc.) and injects the page-specific content. | themes/components/statics/layout.phtml |
Sources: iite/overview.php:12, 21, 23, apps/pages.php:3, apps/translations.json:2
Language and Translation
Internationalization (i18n) is a key feature managed by the controller scripts. The system supports Italian (it), English (en), French (fr), and Spanish (es).
Language Selection
The user's preferred language is stored in the PHP session ($_SESSION['lang']).
- On each page load, the controller script checks for a
langquery parameter (e.g.,?lang=fr). - If present, it updates
$_SESSION['lang']and redirects the user to the same URL without the query parameter to provide a clean address. - If no
langparameter is present, it uses the language from the session, defaulting to'it'(Italian) if the session variable is not set.
// Source: iite/overview.php:4-9
session_start();
if (isset($_GET['lang'])) {
$_SESSION['lang'] = $_GET['lang'];
$cleanUrl = strtok($_SERVER["REQUEST_URI"], '?');
header("Location: $cleanUrl");
exit;
}
// Source: iite/overview.php:11
$lang = $_SESSION['lang'] ?? 'it';
Translation Data Stores
Translations are split into two main files:
apps/pages.php: Contains only the<title>tag content for each page. This is a PHP array loaded by the controller.apps/translations.json: Contains all other text content displayed on the page, such as headers, paragraphs, and button labels. This JSON file is likely loaded and processed within the.phtmlview files or via client-side JavaScript.
apps/pages.php Structure
This file returns a simple associative array.
// Source: apps/pages.php:3-10
return [
'index' => [
'it' => 'Benvenuto in Institute Itech',
'en' => 'Welcome to Institute Itech',
'fr' => 'Bienvenue chez Institute Itech',
'es' => 'Bienvenido a Institute Itech',
],
'iite_overview' => [
'it' => 'Panoramica di Institute Itech',
'en' => 'Overview of Institute Itech',
'fr' => 'Vue d’ensemble de Institute Itech',
'es' => 'Resumen de Institute Itech',
],
// ... more pages
];
The controller uses this array to set the $title variable, with a fallback mechanism to English and then a generic default.
// Source: iite/overview.php:12-14
$page = $_GET['page'] ?? 'iite_overview';
$translations = require __DIR__ . '/../apps/pages.php';
$title = $translations[$page][$lang] ?? $translations[$page]['en'] ?? 'Institute Itech';
Content Rendering
The system uses PHP's output buffering capabilities to separate page-specific content from the master layout.
Controller and View Interaction
The following sequence diagram shows how the components interact to build the final page.
This diagram details the interactions between the controller, data, view, and layout to assemble a page.
Sources: iite/overview.php:13, 21-23, index.php:18-20
Special Page Flags
Controllers can set flags to alter the behavior of the master layout. For example, login.php sets a $hideNavbar variable to true, which the layout.phtml file can use to conditionally hide the navigation bar.
// Source: login.php:23-29
// If we want to hide the navbar for the login page (or others), set this flag.
$hideNavbar = false;
// ...
// Hide navbar if the current page is in the list (fallback to path check)
if (in_array($page, $hideNavbarPages, true) || str_contains($_SERVER['REQUEST_URI'], '/login')) {
$hideNavbar = true;
}
This allows specific pages like the login screen to have a different overall structure without requiring a separate layout file.
Simplified Controllers
Some pages, like research/overview.php, use a simplified version of the controller logic. They define a static title and do not include the language-switching functionality, indicating potential inconsistencies or legacy code within the project.
// Source: research/overview.php:3-11
<?php
$title = "The Research | Institute Itech™";
ob_start();
include __DIR__ . '/../themes/apps/research/overview.phtml';
$output_page = ob_get_clean();
include __DIR__ . '/../themes/components/statics/layout.phtml';
?>
Sources: research/overview.php:3-11, inside/interface.php:3-11
Summary
The page controller system, centered around apps/pages.php and a convention of controller scripts, provides a straightforward yet effective way to manage page rendering and internationalization. By using output buffering and a master layout, it maintains a consistent look and feel while allowing for page-specific content and variations. The separation of translation data for titles (apps/pages.php) and other UI elements (apps/translations.json) defines a clear, if basic, content management strategy.