Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: vhugo_rf en 8 Agosto 2016, 17:54 pm



Título: error al generar sistema spl_autoload_register
Publicado por: vhugo_rf en 8 Agosto 2016, 17:54 pm
Hola cómo están, estoy intentando crear un sistema de autoloading con namespace y MVC al correr en local no hay problema sino al subir los archivos al servidor de producción arroja un error 500.

El servidor de producción tiene

Código:
PHP Version 5.5.36

y en local trabajo con

Código:
PHP Version 5.5.9

el error en el log es el siguiente

Código:
PHP Fatal error:  Class 'lib\Config' not found in /home/*******/public_html/proyecto/app/controller/homeController.php on line 3

mi archivo homeController.php es

Código:
<?php
namespace controller;
$config = \lib\Config::getInstance();
$h = new \lib\service\Home();
new \test\Test();
if(isset($_POST['axn'])):
else:
    require_once("app/view/home/home.phtml");
endif;

este es mi código index

Código:
<?php
$vars = $_REQUEST;
$action = ((!empty($vars['action'])) ? $vars['action'] : "home");
$file = ((is_file("app/controller/" . $action . "Controller.php")) ? "app/controller/" . $action . "Controller.php" : "app/controller/errorController.php");

spl_autoload_register(function($clase){
$DS = DIRECTORY_SEPARATOR;
$className = explode('\\', $clase);
$class = array_pop($className);
$namespace = implode($DS, $className);

$axn = ((!empty($_GET['action'])) ? $_GET['action'] : "home");

$libPath = 'app' . $DS . strtolower($clase) . '.class.php';
$modelPath ='app' . $DS . $namespace . $DS . $axn . 'Model.php';
$contollerPath = 'app' . $DS . $namespace . $DS . $axn . 'Controller.php';
$sqlPath = 'app' . $DS . $namespace . $DS . $axn . '.class.php';
if(!is_file($libPath) &&
    !is_file($modelPath) &&
    !is_file($contollerPath) &&
    !is_file($sqlPath)):
    $contollerPath = 'app' . $DS . $namespace . $DS . 'errorController.php';
    $modelPath ='app' . $DS . $namespace . $DS . 'errorModel.php';
endif;

if(is_readable($libPath)):
    require_once($libPath);
elseif(is_readable($modelPath)):
    require_once($modelPath);
elseif(is_readable($contollerPath)):
    require_once($contollerPath);
elseif(is_readable($sqlPath)):
    require_once($sqlPath);
endif;
 });
 require_once($file);

esta es la estructura de archivos
https://drive.google.com/file/d/0BxtDHt_IfKf6U2xCMXJ6cFdvNzg/view?pref=2&pli=1

Muchas gracias, espero me puedan ayudar


Título: Re: error al generar sistema spl_autoload_register
Publicado por: [u]nsigned en 10 Agosto 2016, 17:02 pm
Los errores 500 generalemnte son por una mala configuracion o conflicto en .htaccess. Podrias publicar su contenido?

Seguramente por eso no te funcionan las rutas relativas, el error que te tira dice que no encuentra la clase lib/Config. O estas usando mal las rutas o tenes las redirecciones de apache mal confguradas.