Correct way to work with Composer in php

Asked

Viewed 64 times

2

Hello, I really like php and for some time I’m using the concept of MVC in my application, but without using Composer and its autoloader. In search to elevate my knowledge, I installed the same and I came to use third party applications using dependencies.

The question is: where MY application is?

I read that you need to add the following code in my Composer.json

    "autoload": {
       "psr-4": {"MeuProjeto\\": "src/"}
    }

But it still doesn’t work, I used the commands:

Composer update | Dump-autoload

and it didn’t work, what would be the problem? the mistake that gives is this:

Fatal error: Class 'Init' not found in C: Inetpub Estudo public index.php on line 33

But using the applications included in the project dependencies (within the vendor folder) no such error occurs thank you

  • Are you using the namespace MeuProjeto; in class Init? Your class is inside the folder src/MeuProjeto? Your application is in the folder src, but if you install as a dependency, the application is normally in vendor/author_user/package_name/src/namespace/*.php

  • @Valdeirpsr boy, did I forget to define the namespace? because the Init.php file was not itself a namespace, it was the initial access file that was redirected to the proper namespace... thank you!

  • And no, I added the code I found in the Poser documentation to my application to stay in the src folder (for my organization)

  • Blz. Managed to solve?

  • I did, buddy, thanks for your help!

No answers

Browser other questions tagged

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