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?
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With