Class not found on remote server

Asked

Viewed 45 times

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'

1 answer

0

Locally it must be working because Windows is usually case-insensitive.

On the server, which should be based on linux, it will be case-sensitive.

You can change the vendor/autoload.php to always convert the path to lowercase, if that is always your rule, or change the use CLASSES\INIT\Init; to represent what’s in filesystem, but then you’ll probably have to change in several files.

Also note that the autoload.php that you’re using was generated by composer change that file may have other consequences.

  • it is. But as you can see in the query, the paths and filenames are correctly defined respecting case-sensitive rule!

  • 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 folder CLASSES\INIT, as you have in the uses, 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.

  • INIT CLASSES Init is not folder. It is namespace!

  • Right! But autoload uses this to know where to get the file you indicate there

  • 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

  • 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 in uses to figure out where to find the specified file and automatically load it, without using include or require, he does it for you.

  • added data at the end of the question. take a look at it please?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.