I cannot mount autoload with PSR-4 for multiple folders and subfolders

Asked

Viewed 146 times

0

I’m trying to pass a project to MVC and then created the following structure:

pasta_projeto
-App
--Controllers
---Classes
--Models
---Classes
--views
---html
-vendor
--Controller
---Action.php
--init
---Bootrstrap.php

I’m creating the file composer.json inside the folder of my project with the following structure:

{
    "name" : "pasta/projeto",
    "require" : {
        "php" : ">=5.3" 
    },
    "minimum-stability" : "alpha",
    "authors" : [
        {
            "name" : "autor",
            "email" : "[email protected]"
        }
    ],
    "autoload": {
        "psr-4": {
            "[Nome da pasta em vendor]\\":"vendor/[Nome da Pasta em vendor]",
            "App\\": "App/"

        }
    },
    "config" : {
        "bin-dir" : "bin"
    }
    }

Running the command on composer dump-autoload -o (terminal) to charge the autoload, my classes when created are with the namespace:

namespace App\[Pasta da Classe];
namespace [Nome da pasta em vendor]\[Pasta da Classe]

By using them:

use App\[Pasta da Classe]\[Nome da classe];
use [Nome da pasta em vendor]\[Pasta da Classe];

The problem is that the PHP does not find the classes that are in the folder vendor, only the folder classes App

PHP Fatal error:  Class 'nomedapastaemvendor\init\Bootstrap' not found
in C:\Users\vinic\Desktop\pasta_projeto\App\Init.php on line 8        
[Tue Mar 20 12:46:38 2018] ::1:62311 [500]: / - Class
'nomedapastaemvendor\init\Bootstrap' not found in
C:\Users\vinic\Desktop\pasta_projeto\App\Init.php on line 8
  • You have to use use \<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>

  • Ops, my failure to use I put the name of the class I am wanting to use, in case the vendor folder did not work

No answers

Browser other questions tagged

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