Answer the question
In order to leave comments, you need to log in
Question about work - COMPOSER - autoload?
I have a question.
In the localhost folder I have an index.php file and a php_classes folder in which I created 2 test classes.
Then I install via composer console to this localhost folder. And I create a file autoload. When I display classes in index.php, they are loaded, all the rules work.
The root folder of the site is localhost.
And if I do this, for example, in the localhost folder I create the APP folder and then in this folder I create the index.php file, the php_classes folder and HERE I install composer, then when I want to display the classes, an
error occurs - Fatal error: Uncaught Error: Class 'php_classes\Worker' not found in C:\OSPanel\domains\localhost\app\index.php
Why is this happening where is my mistake?
Answer the question
In order to leave comments, you need to log in
established practice (names other than the vendor are conditional)
app - current project
public - www root
src - for libs that are planned to be used in other
vendors in the future
composer.json
How to describe your lib in the simplest version
of "autoload": {
"psr-4" : {
"antson\\": "src/antson/"
}
},
in src create folder antson (who is the author), subfolder mylib in it
and
then MySuperPuper.php
<?php
namespace antson\mylib;
class MySuperPuper{
....
}
in the main project
$a = new antson\mylib\MySuperPuper();
or
use antson\mylib\MySuperPuper;
...
$a = MySuperPuper();
This is greatly simplified! We carefully read about PSR and namespace.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question