Folder tree:
jp@JP:/opt/lampp/htdocs/curso$ tree
.
├── clases
│ ├── Conexion.php
│ └── Estudiante.php
├── css
├── imagenes
├── index.php
├── js
└── modulos
├── Controlador.php
└── Enrutador.php
5 directories, 5 files
File index.php
:
<?php
include_once('modulos/Enrutador.php');
include_once('modulos/Controlador.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>POO en PHP</title>
<link rel="stylesheet" href="css/estilos.css">
</head>
<body>
<h1>
Bienvenidos todos los estudiantes
</h1>
<section>
<?php
$enrutador = new Enrutador();
$enrutador->cargarVista($_GET['cargar']);
?>
</section>
</body>
</html>
File Enrutador.php
:
<?php
class Enrutador{
public function cargarVista($vista){
switch ($vista):
case "crear":
include_once('vistas/' . $vista . '.php');
break;
default:
include_once('vistas/error.php');
endswitch;
}
}
?>
Errors when I run it:
Welcome to all students
Notice: Undefined index: load in /opt/lampp/htdocs/curso/index.php on line 21
Warning: include_once (views / error.php): failed to open stream: The file or directory does not exist in /opt/lampp/htdocs/curso/modulos/Enrutador.php on line 13
Warning: include_once (): Failed opening 'views / error.php' for inclusion (include_path = '.: / opt / lampp / lib / php') in / opt / lampp / htdocs / course / modules / Router. php on line 13