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...
You executed the command
php composer dump-autoload
for him to register this code? another question is asked in Laravel?– novic
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.
– Lucas Souza
I got Lucas! what you have /opt/lampp/htdocs/Estudando/app/Usuario/Controller/usuarioController.php on line 1 in this line?
– novic
I believe you meant on line 13, right? There’s this: $connect = new connect();
– Lucas Souza
Show in your question the directory structure
– novic
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.– novic
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.
– Lucas Souza