예제 #1
0
 protected function LoadModel($model)
 {
     $this->Model = 'model/' . strtolower($model) . '.php';
     // Verificamos que exista
     if (!file_exists($this->Model)) {
         ErrorController::Show(5, $this);
     }
     // Guardamos en nuestra variable Models todo los modelos que vamos cargando
     $this->Models[] = $model;
     // Cargamos el modelo
     require_once $this->Model;
     return new $model();
 }
예제 #2
0
 public function __CONSTRUCT($reload = false)
 {
     //	0 => 'Raíz del Proyecto' 1=> 'index.php' 1 => 'Controlador'	3 => 'Accion' 4 => 'Parametros Adicionales'
     $this->Uri = explode('/', substr($_SERVER['REQUEST_URI'], 1, strlen($_SERVER['REQUEST_URI']) - 1));
     // Preguntamos si existe en la URL actual una llamada a algun controlador especifico
     if (count($this->Uri) == 2) {
         $this->Controller = _DEFAULT_CONTROLLER_;
     } elseif (count($this->Uri) > 2) {
         // Si en la URL por defecto no hay referencia de un controlador, cargamos el que esta por defecto
         if ($this->Uri[2] == '' || $this->Uri[2] == '/') {
             $this->Controller = _DEFAULT_CONTROLLER_;
         } else {
             // Verificamos si es un Area
             if (is_dir(_BASE_FOLDER_ . 'controller\\' . $this->Uri[2])) {
                 $this->Area = $this->Uri[2];
                 $this->Controller = str_replace('/', '', $this->Uri[3]);
             } else {
                 $this->Controller = str_replace('/', '', $this->Uri[2]);
             }
         }
         // Si se ha especificado la acción
         $i = $this->Area == null ? 3 : 4;
         if (isset($this->Uri[$i])) {
             if ($this->Uri[$i] != '' && $this->Uri[$i] != '/') {
                 $this->Action = str_replace('/', '', $this->Uri[$i]);
             }
         }
     }
     if (!$reload) {
         // Guardamos la ruta del controlador
         $_Controller = 'controller/' . ($this->Area == null ? '' : $this->Area . '/') . $this->Controller . 'controller.php';
         // Verificamos que la vista exista
         if (!file_exists($_Controller)) {
             ErrorController::Show(1, $this);
         }
         // Cargamos el fichero
         require_once $_Controller;
         $ControladorActual = $this->Controller . 'controller';
         $AccionActual = $this->Action;
         // Creamos una instancia del controlador actual y ejecutamos su accion
         $c = new $ControladorActual();
         // Verificamos si la acción existe
         if (!method_exists($c, $this->Action)) {
             ErrorController::Show(2, $this);
         }
         // Ejecutamos la acción actual
         $c->{$AccionActual}();
     }
 }
예제 #3
0
 public function __CONSTRUCT()
 {
     // Recuperamos nuestra cadena de conexión
     $ConnectionString = explode('|', _DB_CONNECTION_STRING_);
     try {
         // Instanciamos PDO
         $this->Link = new PDO($ConnectionString[0], $ConnectionString[1], $ConnectionString[2]);
         // Le indicamos que nos muestre los errores
         $this->Link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         // Si hay un error llamamos al ErrorController
         ErrorController::Show(4, $e);
     }
     return $this;
 }