Directory error with spl_autoload_register

0

I'm having an error using autoloader.

Autoloader.php file:

<?php

function carregarClasses($classe) {
    require_once __DIR__ . '/' . $classe . '.php';
}

spl_autoload_register('carregarClasses');

Error:

  

Warning:   require_once (/home/neowix/public_html/erp/pages/classes/Conexao.php):   failed to open stream: No such file or directory in   /home/neowix/public_html/erp/pages/classes/autoload.php on line 4

     

Fatal error: require_once (): Failed opening required   '/home/neowix/public_html/erp/pages/classes/Conexao.php'   (include_path = '.: / opt / php56 / lib / php') in   /home/neowix/public_html/erp/pages/classes/autoload.php on line 4

    
asked by anonymous 11.07.2016 / 17:47

1 answer

0

The constant __DIR__ returns the current file directory, of the file where script is running. In your case, /home/neowix/public_html/erp/pages/classes/autoload.php

When you mount the path to autoload the files containing the classes, the path will be:

/home/neowix/public_html/erp/pages/classes/NomeDaClasse.php

If the path is mounting correctly, make sure the files have the correct nomenclature. In Linux, the nomenclature is case sensitive. Example, if the file exists with name "connection.php", it will not be found.

    
11.07.2016 / 18:05