Hi, I'm fighting a while ago with the php route system but I still have the same problem. The classes work correctly, the problem is when I call the class from the controller, the class route I call works, but the routes that class calls are not found, if it is better understood with the code and the error:
Controller:
<?php
require_once '../models/DAO/HermandadDAO.php';
$accion = $_REQUEST['accion'];
switch ($accion) {
case "insertar":
$dao = new HermandadDAO();
$values = array(
"nombre" => $_REQUEST['nombre']
);
$dao->insertar($values);
break;
}
DAO brotherhood class:
<?php
require_once '../entities/Hermandad.php';
require_once 'AbstractDAO.php';
class HermandadDAO extends AbstractDAO {
public function insertar($arrayValues) {
$values = array(
Hermandad::NOMBRE => $arrayValues["nombre"]
);
return parent::insertar(Hermandad::TABLA, $values);
}
}
AbstractDAO Class:
<?php
require_once '../../database/Conexion.php';
class AbstractDAO {
private $conexion;
private $dbHandler;
public function __construct() {
$this->conexion = new Conexion();
$this->dbHandler = $this->conexion->getConexion();
if (!$this->dbHandler) {
echo "Error al conectar con la base de datos";
}
}
public function insertar($tabla, $values) {
$sql = "";
$sql .= "INSERT INTO " . $tabla;
$sql .= " (" . implode(",", array_keys($values)) . ") ";
$sql .= "VALUES ('" . implode("','", array_values($values)) . "');";
$query = mysqli_query($this->dbHandler, $sql);
if ($query) {
return true;
} else {
return false;
}
}
}
and then the error says that the class brotherhoodDAO does not find the class Brotherhood, but only happens to me calling it from the controller, when I try it from the brotherhoodDAO if it works.