Class not found in namespace

Asked

Viewed 641 times

0

I’m trying to use a class by using the namespace, but it always generates this error:

Fatal error: Uncaught Error: Class 'Database\connect' not found in /opt/lampp/htdocs/Estudando/app/Usuario/Controller/usuarioController.php:13 Stack trace: #0 /opt/lampp/htdocs/Estudando/index.php(11): app\Usuario\Controller\usuarioController->nome() #1 {main} thrown in /opt/lampp/htdocs/Estudando/app/Usuario/Controller/usuarioController.php on line 13

My Commodore is this way:

{
    "autoload" : {
      "psr-4":{
        "app\\":"app",
        "Database\\":"Database"
      }
    },
    "require": {
        "twig/twig": "^2.4"
    }
}

The class I want to instantiate is that way:

namespace Database;

  class connect {
     ....
  }

And this is the class I’m calling:

namespace app\Usuario\Controller;
use \app\Usuario\Views\usuarioView;
use Database\connect;

  class usuarioController {
    public function nome(){
    }
  }

I can use the namespaces of the app/ path quiet, but now that I needed to add the database/ I’m not getting...

Estrutura do projeto

  • You executed the command php composer dump-autoload for him to register this code? another question is asked in Laravel?

  • I’ve already registered the code yes, I’m starting this MVC standard, I’m not using any framework. It’s more for study even.

  • I got Lucas! what you have /opt/lampp/htdocs/Estudando/app/Usuario/Controller/usuarioController.php on line 1 in this line?

  • 1

    I believe you meant on line 13, right? There’s this: $connect = new connect();

  • Show in your question the directory structure

  • 1

    Let me try to help you inside the vendor folder has Composer folder inside an autoload_psr4.php file check inside it if it exists 'Database\\' => array($baseDir . '/Database'), or if you place the contents of that file differently.

  • 1

    Hello, apparently the first time I registered it was as ' Database ' when di the dump-autoload Composer it started working. Anyway I appreciate the help, just seeing the contents of autoload_psr4.php is that I could realize that there was something wrong.

Show 2 more comments
No answers

Browser other questions tagged

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