1
I have the following file index php.
<?php
require_once 'global/erros/erros.ini';
require_once 'vendor/autoload.php';
use CLASSES\INIT\Init;
new Init();
?>
And the next class Init.php
<?php
namespace CLASSES\INIT;
use CLASSES\CONFIG\Config;
class Init extends Config {
protected function iniciaRotas() {
$ar["home"] = array("rota"=>"/crud/", "controle"=>"site", "acao"=>"index");
$ar["index"] = array("rota"=>"/crud/index", "controle"=>"site", "acao"=>"index");
$ar["admin"] = array("rota"=>"/crud/admin", "controle"=>"admin", "acao"=>"index");
$this->configRotas($ar);
}
}
?>
And the next autoload_ps4
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'CLASSES\\' => array($baseDir . '/classes'),
);
So locally (localhost) works.
But when I go up to the server it’s wrong:
Fatal error: Class 'CLASSES\INIT\Init' not found in
/var/www/html/funerariasaopedro.net.br/web/crud/index.php on line 8
Doesn’t make much sense!
Tree
\
\index.php
\classes\
\classes\init\
\classes\init\Init.php
Like I stopped at composer.json
to generate the autoload_psr4.php
?
In this way:
'CLASSES\\UTIL\\' : '/classes/util',
'CLASSES\\MVC\\CONTROLES\\' : '/classes/mvc/controles'
Or that?
'CLASSES\\UTIL\\Util\\' : '/classes/util/Util.php',
'CLASSES\\MVC\\CONTROLES\\Administradores\\' : '/classes/mvc/controles/Administradores.php',
'CLASSES\\MVC\\CONTROLES\\Base\\' : '/classes/mvc/controles/Base.php'
it is. But as you can see in the query, the paths and filenames are correctly defined respecting case-sensitive rule!
– Carlos Rocha
I don’t know, I’m pretty sure that’s the problem, because the mistake says
Fatal error: Class 'CLASSES\INIT\Init' not found in
showing that you are trying to access a folderCLASSES\INIT
, as you have in theuses
, and in the list of folders you show in the exampleÁrvore
They have lowercase. The code also doesn’t indicate that there is another problem, because it works on your location, and I assume that all the files are on the server.– Leite
INIT CLASSES Init is not folder. It is namespace!
– Carlos Rocha
Right! But autoload uses this to know where to get the file you indicate there
– Leite
The namespaces have to be exactly the names of the folders? Is that it? If it is, it’s really wrong. But I took example on the internet
– Carlos Rocha
It doesn’t have to be the path as it is in the filesystem, but it usually is. The
autoload
is using the path specified inuses
to figure out where to find the specified file and automatically load it, without usinginclude
orrequire
, he does it for you.– Leite
added data at the end of the question. take a look at it please?
– Carlos Rocha