I am new to slim framework and can't figure out how to use autoloader to autoload my classes.
I created app/models/myclass.php, but, of course, when I try to use it, I get a class that is not found. I'm not sure if this is the right way to autoload classes or names that I should use. Should I do this through a .json composer? I browse the web for several hours without any solid answer.
UPDATE
I managed to do this:
- added model to: app / src / Model / Client.php
- added
namespace App\Model;to Client.php - Added the following to depedencies.php:
$container['App\Model\Client'] = function ($c) {
return new App\Model\Client();
};
and routes.php:
$app->get('/client/ping/{id}', function ($request, $response, $args) {
$container = $this->getContainer();
$client=$container['App\Model\Client'];
...
...
}
source
share