Ver Mensaje Individual
  #8 (permalink)  
Antiguo 24/01/2016, 12:36
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: Estructurar Sistema en PHP

Hola a todos, verán estuve intentando hacer lo que me dijeron a mi da este error:

Fatal error: Class 'FrontendBundle\Controller\MainController' not found in /var/www/html/amnesia_1_hmvc/index.php on line 35

El código es usé es este:

<?php
define("APPLICATION_PATH", dirname(__FILE__));
define("DS", DIRECTORY_SEPARATOR);
spl_autoload_register(function($clase){
// project-specific namespace prefix
$prefix = 'App\\Controller.php';

// base directory for the namespace prefix
$base_dir = __DIR__ . '/Src/';

// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $clase, $len) !== 0) {
// no, move to the next registered autoloader
return;
}

// get the relative class name
$relative_class = substr($clase, $len);

// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';

// if the file exists, require it
if (file_exists($file)) {
require $file;
}
});
$controlador = (!empty($_GET['c'])) ? ucwords($_GET['c']) . 'Controller' : "MainController";
$accion = (!empty($_GET['a'])) ? $_GET['a'] : "index";
try{
$controlador = "Controller\\" . $controlador;
$controlo = new $controlador();
$controlo->$accion();
}
catch (Exception $ex) {
echo $ex->getMessage();
}

En el repositorio, no lo subí todavía pero no sé cual es el error y que debo cambiar.

Espero respuestas y saludos.