Answer the question
In order to leave comments, you need to log in
Why is Slim + PHP-DI throwing Fatal error: Cannot declare class when requesting a controller?
Good afternoon, I created a project on SLIM + PHP-DI, connected `php-di/slim-bridge` and inherited the application
class App extends \DI\Bridge\Slim\App
{
protected function configureContainer($builder)
{
$builder->addDefinitions(dirname(__DIR__) . '/app/config.php');
}
}
$app->get('/game/{id}', ['fey\Api\v1\Controllers\GameController', 'show']);
Fatal error: Cannot declare class Api\v1\Controllers\GameController, because the name is already in use in
Answer the question
In order to leave comments, you need to log in
The second argument to get expects a callable as I understand it.
And in your case, it should most likely be something like
use Api\v1\Contollers\GameController;
$app->get('/game/{id}', [new GameController(), 'show']);
/* Или
$app->get('/game/{id}', [GameController::class, 'show']);
*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question