0
This "class" needs to be in the composer.json
, PHP cannot guess where it is located and the use
is not equal to include
as I explained in:
The Composer (which Slim uses), makes use of the spl_autoload
that this yes "program" its scripts to locate the classes, in this case Composer uses the composer-autoload
, then you need to add it to your composer.json
, thus:
"autoload": {
"psr-4": {
"Slim\\": "Slim",
"Classes\\": "Classes"
}
},
The Classes\\
is the prefix to be identified by the namespace, and "Classes"
is the folder where they are located, should look similar to this:
{
"name": "slim/slim",
"type": "library",
"description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs",
"keywords": ["framework","micro","api","router"],
"homepage": "https://slimframework.com",
"license": "MIT",
"authors": [
{
"name": "Josh Lockhart",
"email": "[email protected]",
"homepage": "https://joshlockhart.com"
},
{
"name": "Andrew Smith",
"email": "[email protected]",
"homepage": "http://silentworks.co.uk"
},
{
"name": "Rob Allen",
"email": "[email protected]",
"homepage": "http://akrabat.com"
},
{
"name": "Gabriel Manricks",
"email": "[email protected]",
"homepage": "http://gabrielmanricks.com"
}
],
"require": {
"php": ">=5.5.0",
"pimple/pimple": "^3.0",
"psr/http-message": "^1.0",
"nikic/fast-route": "^1.0",
"container-interop/container-interop": "^1.2",
"psr/container": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "^2.5",
"phpunit/phpunit": "^4.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"autoload": {
"psr-4": {
"Slim\\": "Slim",
"Classes\\": "Classes"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "php vendor/bin/phpunit",
"phpcs": "php vendor/bin/phpcs"
}
}
After adding in Composer.json run the command:
composer dump
Or run the command composer update
if you want that in addition to updating the classes it also download the dependencies of Slim and other packages that you added
This way it will be available on Poser-autoload
Read more about Composer
The basic:
- https://getcomposer.org/doc/01-basic-usage.md
- https://getcomposer.org/doc/01-basic-usage.md#autoloading
Some useful links in Portuguese of answers I wrote:
How you are declaring the Validation class call?
– David Alves