Unlike the back end, the front end will use modules rather than components.
Each module will be based on the MVC architectural pattern.
The website's index.php receives the URL's GET request and calls the relevant page based on the first argument.
Our index.php will be relatively simple: it includes the requested page. The page contains the logic and calls all its modules, which implement the MVC model. Each module inherits a run method, which the page uses to create it.
The system analyses the URL in the request. If the first argument identifies an existing page, it includes and interprets that page.
PAGE → LOAD MODULES → HTML RESPONSE
public function procesarPlantilla(){
$plantilla = file_get_contents($this->rutaPlantilla);
preg_match_all('/\[\[.*\]\]/i', $plantilla, $this->_modulos);
$this->_modulos = $this->cargaModulos($this->_modulos[0]);
if($this->_modulos = $this->procesaModulos($this->_modulos))
foreach($this->_modulos as $mod)
$plantilla = str_replace($mod->string,$mod->buffer, $plantilla);
$this->SetPlantillaProcesada($plantilla);
}
The previous code uses a regular expression to find modules contained in a page, looking for strings such as '[[noticias::index::ultimahora]]'. After processing each module, it replaces these strings with the output buffer obtained from that module's run method.
The page concept and page selector are very practical. They make the code more human-readable by organising it into files containing module calls, just as we see them on the website.
This degree of encapsulation and organisation would also allow caching at different levels, including pages and even modules. Here, caching is implemented at page level in index.php itself, but the system is ready for module-level caching. That could suit systems where particular areas, such as the user area, cannot be cached.