Hello!
I need your help. I want auto-includes my class to my project. But composer auto load don’t work. Please, help me.
Project:
src
—> composer.json
—>public–>
----------------->index.php
—>classees–>
------------------->User.php
Project/src/classes/User.php
Project/src/public/index.php
Project/src/composer.json
– src/publi/index.php - https://pastebin.com/17c41v0g
– src/composer.json - https://pastebin.com/KnLGUsU7
This isn’t a Slim issue, but try this:
"psr-4": {
"Class\\": "src/classes/"
}
In your User.php at the top:
<?php
namespace Class;
class User {
...
}
odan
3
Just some general tips:
- The
src/
directory is for the application specific PHP classes only.
- Put your
User.php
class into the src/
sub-directory
- The
public/
directory should not be under the src/
directory
-
composer.json
and vendor/
directory should be on top of the project root
- Example: https://github.com/php-pds/skeleton
In your composer.json define the namespace paths like this:
"autoload": {
"psr-4": {
"App\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests"
}
},