Answer the question
In order to leave comments, you need to log in
How to organize class autoloading in Slim Framework?
Good night friends.
I decided to get acquainted with Slim and already picked up a project for training. I also work with Laravel, so namespace's have already become a habit. I installed the slim/slim-skeleton package first.
Slim has the ability to specify in routes which class and method to call. Fine.
But what about the autoloading of these very classes? I made some "crutch", for starters:
$container = $app->getContainer();
// Руками подключаю файл с нужным классом
require __DIR__ . '/Controllers/Controller.php';
// Помещаю в контейнер
$container['Controller'] = function ($container) {
return new Src\Controllers\Controller();
};
Answer the question
In order to leave comments, you need to log in
As usual, I asked and answered myself.
But I think it will be useful to everyone else who has the same question.
It is necessary to register in composer.json:
"autoload": {
"psr-4": {
"App\\": "src/App"
}
}
jsfiddle.net/davidThomas/7F7Vn/1 - from here: stackoverflow.com/questions/20305594/circle-with-t...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question