I\'m new to slim framework, and can\'t figure out how to use the autoloader to autoload my classes.
I created a app/models/myclass.php
but of course wh
For autoloading of own classes you should use Composer
by adding some options to your composer.json
:
{
"require": {
"slim/slim": "^3.9"
},
"autoload": {
"psr-4": {
"My\\Namespace\\": "src/"
}
}
}
// index.php
require 'vendor/autoload.php';
$app = new \Slim\App();
$myClass = new \My\Namespace\MyClass();
After running composer update
composer will register your own namespaces and will autoload them for you.
Add this in composer.json file Where app1 is the name of the folder you want to Autoload.
"autoload": {
"psr-4":{
"app1\\": "anything"
}
}
After doing this run this in cmd (via composer)
composer dump-autoload -o