I have an Article class with a __construct function that contains an include:
class Articulo{
private $imagen = '';
private $texto = '';
private $titulo = '';
private $id;
private $db;
private $conexion;
function __construct(){
include 'conexion/Conexion.php';
$db = new Conexion;
$this->conexion = $db->connect();
}
Well, depending on where you call that function from, it gives a location error or not. If I call from index.php or from admin.php there is no problem. But when I call from sem-article it tells me: include(connection/Conexion.php): failed to open stream: No such file or directory
The problem is that in the include you use relative paths and for it to work in sub-folders you have to use absolute ones. Something like that:
Notice that semi-article is located in the folder controler. So if you make an include from that location to Connection.php you should make an include like this:
My personal recommendation is that you don't include inside a constructor.