Código PHP:
$controlador = new $controlador;
Cita:
/index.phpWarning: Missing argument 1 for Controller::__construct(), called in /opt/lampp/htdocs/MicroMVC/index.php on line 20 and defined in /opt/lampp/htdocs/MicroMVC/index.php on line 25
Warning: Missing argument 2 for Controller::__construct(), called in /opt/lampp/htdocs/MicroMVC/index.php on line 20 and defined in /opt/lampp/htdocs/MicroMVC/index.php on line 25
Warning: Missing argument 3 for Controller::__construct(), called in /opt/lampp/htdocs/MicroMVC/index.php on line 20 and defined in /opt/lampp/htdocs/MicroMVC/index.php on line 25
Warning: Missing argument 2 for Controller::__construct(), called in /opt/lampp/htdocs/MicroMVC/index.php on line 20 and defined in /opt/lampp/htdocs/MicroMVC/index.php on line 25
Warning: Missing argument 3 for Controller::__construct(), called in /opt/lampp/htdocs/MicroMVC/index.php on line 20 and defined in /opt/lampp/htdocs/MicroMVC/index.php on line 25
Código PHP:
<?php
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=UTF-8');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', realpath(dirname(__FILE__)).DS);
define('APP_PATH', ROOT.'aplicacion'.DS);
$argumentos = isset($_GET['url']) ? explode('/', $_GET['url']) : array() ;
$controlador = ($controlador = strtolower(array_shift($argumentos))) ? $controlador : 'index' ;
$metodo = ($metodo = strtolower(array_shift($argumentos))) ? $metodo : 'index' ;
$controlador = $controlador.'Controlador';
$rutaControlador = ROOT.'controladores'.DS.$controlador.'.php';
if (file_exists($rutaControlador)) {
require_once $rutaControlador;
$controlador = new $controlador;
$metodo = method_exists($controlador, $metodo) ? $metodo : 'index';
}
class Controller {
public function __construct($controlador, $metodo, $argumentos) {
//echo $controlador;
//echo $metodo;
//foreach ($argumentos as $argumento) echo $argumento;
}
}
new Controller($controlador, $metodo, $argumentos);
?>
Código PHP:
<?php
class indexControlador extends Controller {
public function index() {
echo 'Método index';
}
public function ver() {
echo 'Método Ver';
}
}
?>