Search code examples
phpapiframeworkscomposer-phpslim

Class not found in PHP Slim framework


I installed slim with composer. After testing it, it shows me the following error. Can't figure out why.

Fatal error: Class 'Slim\Container' not found in C:\projectname\vendor\slim\slim\Slim\App.php on line 77

index.php

<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

require_once dirname(__FILE__) . '/../../vendor/autoload.php';
require dirname(__FILE__) . '/config.php';

$app = new \Slim\App($configuration);

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");

    return $response;
});

$app->run();

composer.json

{
    "require": {
        "monolog/monolog": "1.23.0",
        "j4mie/paris": "v1.5.6",
        "slim/slim": "3.10.0"
    }
}

Solution

  • Nevermind, realized that I had Slim installation broken. Removed slim from composer.json, saved and updated the composer, Then add again and do the same. Problem solved. Thanks anyway!