Ver Mensaje Individual
  #5 (permalink)  
Antiguo 22/08/2010, 21:11
Avatar de mayid
mayid
Colaborador
 
Fecha de Ingreso: marzo-2009
Ubicación: BsAs
Mensajes: 4.014
Antigüedad: 15 años, 2 meses
Puntos: 101
Respuesta: seleccionar controladores y vistas en MVC

Bueno, este es el FrontController según lo que pude concebir hasta ahora:

Código PHP:
class FrontController{    

    var 
$controller;
    
    function 
__construct(){
        
        
$this->defineConstants(); // url and path constants
        
$this->callController();        
    }    
    
    public function 
defineConstants(){ 
        
        
// If moving to another server, we must update this!
        
if (strpos($_SERVER["HTTP_HOST"], "localhost") !== false){
            
define('APP''http://localhost/AoI/AoITutorials/application/');
            
define('WEB''http://localhost/AoI/AoITutorials/web/'); // localhost for development
        
}
        else {    
            
define('APP''http://www.artofillusion.com.ar/application/');
            
define('WEB''http://www.artofillusion.com.ar/AoITutorials/');
        }
        
        
// fix for domain and subdomain issue: aoi-castellano / artofillusion.com.ar
        
if (strpos($_SERVER["HTTP_HOST"], "castellano") !== false){
            
header("Location: ".WEB);  // redirect.
        
};
        

        
define('WEB_REL_PATH'$_SERVER['DOCUMENT_ROOT']."AoI/AoITutorials/"."web/");        
        
define('APP_REL_PATH'$_SERVER['DOCUMENT_ROOT']."AoI/AoITutorials/"."application/");
        
define('APP_LIB'APP_REL_PATH.'Library/');    

        
// html <head> related constants (absolute path)
        
define('LIBRARY_DIR''Library/');
        
define('LINK_CSS''Library/styles/');
        
define('IMG_DIR''Library/images/');
                
        
// html <body> related constants (for including ui images, etc)                
        
define('CONTROLLERS'APP_REL_PATH.'controllers/');
        
define('TEMPLATES'APP_REL_PATH.'templates/');            
        
define('LIBRARY'WEB_REL_PATH.'Library/'); 
        
define('CSS_DIR'LIBRARY.'styles/');
    
    }
    
    private function 
callController(){
        
        
// get controller
        
if(! empty($_GET['controller']))
              
$controllerName $_GET['controller'] . 'Controller';
        else
              
$controllerName "MainPageController";
        
        
// get action
        
if(! empty($_GET['action']))
            
$actionName $_GET['action'];
        else
            
$actionName "index";
    
        
// check controller existence    
        
if(is_file(CONTROLLERS.$controllerName.".php"))
            require 
CONTROLLERS.$controllerName.".php";
        else
            die(
'Unexisting page - Go to index?');
        
        
// check action existence    
        
if (is_callable(array($controllerName$actionName)) == false)
        {
             die(
'Unexisting action - Go to index?');
        }
        
        
// instantiate the controller
        
$controller = new $controllerName();
        
$controller->$actionName();
        
$controller->callView();    
    }