我想在子目录中使用Slim 3,但似乎无法加载它。所有文件都包含在子目录中,包括composer.json。这是我的composer.json:
"require": {
"slim/slim": "3.0.0-RC1"
}
这是我的剧本:
<?php
require "vendor/autoload.php";
use \Slim\Slim;
$app = new \Slim\Slim();
$app->get('/subdirectory/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
我尝试了很多东西,包括Class Slim not found when installing slim with composer和PHP Fatal error: Class 'Slim' not found。不幸的是,他们没有解决我的问题。
我得到的错误是Fatal error: Class 'Slim\Slim' not found in ... on line 5
,对应$app = new \Slim\Slim();
。
任何人都知道我缺少什么?
答案 0 :(得分:18)
似乎Slim3 is not using Slim as main class name but App。
所以你的代码应该是:
<?php
require "vendor/autoload.php";
use \Slim\App;
$app = new App();
$app->get('/subdirectory/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();