0
To learning to use the standard Composer psr-4, the class is not being found.
My index where the user class is not found:
<?php
require_once ('vendor/autoload.php');
$user = new \App\Vendas\Usuario();
$user->cadastrar('David', 30);
$p1 = new \App\Vendas\Produto();
$p2 = new \App\Vendas\Produto();
$p1->cadastrar(1, 'produto1');
$p2->cadastrar(2, 'produto2');
$c = new \App\Vendas\Compra();
$c->cadastrar( array('p1' => $p1, 'p2' => $p2), $user);
echo $c->imprimir();
$e = new \App\Estoque\Estoque();
echo $e->getTotal();
?>
My file Composer.json:
{
"autoload":
{
"psr-4":{"App\\":"App/"}
}
}
Directory structure:
App
---Vendas
Compra.php
Usuario.php
Produto.php
---Estoque
Produto.php
Estoque.php
---vendor
composer.json
index.php
The directory
vendor
is insideApp
?– Woss
Try to change
App/
for./
on Composer and update (composer dump-autoload
)– Costamilam
@Anderson Carlos Woss This inside App yes.
– user122195
If you’re in
App/vendor
, in hisindex.php
should berequire_once('App/vendor/autoload.php')
, otherwise you won’t be able to include the file. The question is, whyvendor
is inApp
?– Woss
And vendor should be where? The solution of @Guilherme Gostar worked, I wanted to understand why.
– user122195
It’s all in App.
– user122195