Require_once not being able to access file

0

I'm not able to include pages to my controle_login.php file as it generates the following errors:

  

Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in C: \ xampp \ htdocs \ Model_MVC \ controlles \ control_login.php on line 2

  Warning: require_once (ABSPATH / models / model_login): failed to open stream: No such file or directory in C: \ xampp \ htdocs \ Model_MVC \ controlles \ control_login.php on line 2

  

Fatal error: require_once (): Failed opening required 'ABSPATH / models / model_login' (include_path = 'C: \ xampp \ php \ PEAR') in C: \ xampp \ htdocs \ Model_MVC \ controls \ control_login.php on line 2

I'll post the codes, because there are weeks that I can not understand what's going on.

Config.php file

Index.phpfile

Filecontrol_login.php(thisfileisinsideafoldercalledcontrols)

<?phprequire_onceABSPATH.'/models/model_login.php';classControladorextendsControle_login{publicfunction__construct(){$obj=newControle_login;}

Filemodel_login.php(thisfileisinsidethemodelsfolder)

<?phprequire_onceABSPATH.'conexao.php';classControle_login{private$con;publicfunction__construct{$con=newConexao();}publicfunctioncontrole_acesso($usuario,$senha){$this->setUsuario($usuario);$this->setSenha($senha);$consulta=$this->con->conectar()->prepare("SELECT COUNT(*) AS total FROM login WHERE usuario=:usuario AND senha=:senha");
        $consulta->bindParam(":usuario", $this->usuario);
        $consulta->bindParam(":senha", $this->senha);
        $consulta->execute();
        $linha = $consulta->fetch(PDO::FETCH_ASSOC);
        return $linha['total'];
    }

}

Folder structure:

    
asked by anonymous 21.01.2018 / 18:35

1 answer

3

The error occurs because the ABSPATH variable is being declared inside the config.php file, so for you to use it inside other files it is necessary to load the config.php file before.

Since your controllers and models folders are in the same directory as the config.php file you can import as follows before using the ABSPATH constant:

require_once dirname(__FILE__)."/../config.php";

For example, your controle_login.php file looks like this:

<?php
require_once dirname(__FILE__)."/../config.php";
require_once ABSPATH.'/models/model_login.php';

class Controlador extends Controle_login{

    public function __construct(){
        $obj = new Controle_login;
    }
  

NOTE: The .. (colon) in the directory path has the function of   return a folder.

    
21.01.2018 / 18:47