Por otro lado, me acabo de dar cuenta de que solo tengo una vista, y me parece que tendría que tener varias. Por ejemplo, uno para manejar todo lo relacionado al login.
Código PHP :
<?php class FrontController{ var $controller; var $dbObject; var $phpvars; var $contentsVars; function __construct(){ include "controllers/BaseController.php"; $baseController = new BaseController(); $baseController->defineConstants(); include "models/Model.php"; $this->dbObject = new dbConsults(); /* Translations for the UI */ $this->phpvars = $baseController->varsConsult($this->dbObject); // utf-8 fixer include (APP_LIB."fixEncoding.php"); $this->includeControllers(); /*** init View ****/ include "views/View.php"; $View = new View(); $View->prepareContents($this->phpvars, $this->contentsVars); $View->render(); // display view } private function includeControllers() { if (isset($_GET['login'])) { include "controllers/LoginController.php"; $LoginController = new LoginController($this->dbObject); $this->contentsVars['usersData'] = $LoginController->checkUser(); } elseif (isset($_GET['register'])) { include "controllers/RegistrationController.php"; $RegistrationController = new RegistrationController($this->dbObject); $this->contentsVars['usersData'] = $RegistrationController->registerUser(); } elseif (isset($_GET['logout'])) { include "controllers/LoginController.php"; $LoginController = new LoginController($this->dbObject); $LoginController->logout(); } elseif (isset($_GET['lostpassword'])) { include "controllers/RememberPassController.php"; $RememberPassController = new RememberPassController($this->dbObject); $this->contentsVars['usersData'] = $RememberPassController->rememberPassword(); } elseif (!isset($_GET['load']) and (FILENAME == "index")) { include "controllers/MainPageController.php"; $MainPageController = new MainPageController(); $this->contentsVars['tutorialsList'] = $MainPageController->listTutorials($this->phpvars, $this->dbObject); } else{ include "controllers/PageController.php"; $PageController = new PageController($this->dbObject); $this->contentsVars['theContents'] = $PageController->printPageContents(); } include "controllers/MenusController.php"; $MenusController = new MenusController($this->dbObject); $this->contentsVars['mainLinks'] = $MenusController->printMainMenu( $this->phpvars ); @$this->contentsVars['relPages'] = $MenusController->printSecondaryMenu( $contentsVars['theContents']['relatedPages'] ); include "controllers/TagsController.php"; $TagsController = new TagsController($this->dbObject); $this->contentsVars['theTags'] = $TagsController->tag_cloud(); } } ?>
Código PHP :
<?php Class View{ var $template; var $CSS_filename; var $availableLanguages; var $contents; function __construct(){ $whichTPL = $this->chooseTemplate(); $this->setTemplate($whichTPL); $this->listStyles(); include (APP_LIB."availableLanguages.php"); $this->availableLanguages = $availableLanguages; } public function render() { echo $this->contents; } private function chooseTemplate(){ if ( isset($_GET['login']) ) $response = TEMPLATES."login.tpl.php"; elseif ( isset($_GET['register']) ) $response = TEMPLATES."registration.tpl.php"; elseif ( isset($_GET['lostpassword']) ) $response = TEMPLATES."lostpassword.tpl.php"; elseif(isset($download)) $response = TEMPLATES."contents.download.tpl.php"; elseif(!isset($_SESSION['name'])) $response = TEMPLATES."contents.NoLogued.tpl.php"; elseif(isset($_SESSION['name'])) $response = TEMPLATES."contents.Logued.tpl.php"; return $response; } public function setTemplate($whichTPL) { $this->template = $whichTPL; } public function prepareContents($phpvars, $contentsVars ) { @$flagsDef = $this->listFlags(); foreach ($contentsVars as $key => $value) { $$key = $value; } ob_start(); include $this->template; $this->contents = ob_get_clean(); } function listStyles(){ // display a list of styles to visualizate the web page $puntos = array('.', '..'); $listado = array_diff(scandir(CSS_DIR), $puntos); foreach($listado as $elemento) { if(is_dir($elemento)) continue; $subdivide = pathinfo($elemento); $extension = strtolower($subdivide['extension']); $nombre_archivo = $subdivide['filename']; if (is_file(CSS_DIR.$elemento) and $extension == "css") { $response[] = $nombre_archivo; } } $this->CSS_filename = $response; } function listFlags(){ $lang = $_SESSION['lang']; // Display country flags $i = 0; foreach ($this->availableLanguages as $listLang){ if (("_".$listLang == "_".$lang) or ($listLang == $lang)) { $mark = "class=\"markedLang\""; } else { $mark = ""; }; $response[$i]['listLang'] = $listLang; $response[$i]['classMark'] = $mark; $i++; } return $response; } function highlightScope($scope){ if (SCOPE == $scope) $highlight = 'class="markedLang"'; else $highlight = ""; return $highlight; } } ?>