Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'Slim\Slim' not found with composer

I want to use Slim 3 in a subdirectory, but cannot seem to load it. All files are contained in the subdirectory, including composer.json. Here is my composer.json:

"require": {
    "slim/slim": "3.0.0-RC1"
}

Here is my script:

<?php
require "vendor/autoload.php";
use \Slim\Slim;

$app = new \Slim\Slim();
$app->get('/subdirectory/hello/:name', function ($name) {
    echo "Hello, $name";
});
$app->run();

I tried many things, including Class Slim not found when installing slim with composer and PHP Fatal error: Class 'Slim' not found. Unfortunately, they didn't solve my problem.

The error I get is Fatal error: Class 'Slim\Slim' not found in ... on line 5, which corresponds to $app = new \Slim\Slim();.

Anyone know what I'm missing?

like image 552
Kelly Keller-Heikkila Avatar asked Oct 19 '15 14:10

Kelly Keller-Heikkila


1 Answers

It seems that Slim3 is not using Slim as main class name but App.

So your code should be:

<?php
require "vendor/autoload.php";
use \Slim\App;

$app = new App();
$app->get('/subdirectory/hello/:name', function ($name) {
    echo "Hello, $name";
});
$app->run();
like image 180
mTorres Avatar answered Sep 19 '22 15:09

mTorres