我正在尝试构建一个silex应用程序.我的文件结构是:
ROOT/
/App/
/Controller/{IndexController.php}
/Config/{dev.php,prod.php,route.php}
/vendor
/web/{index.php, index_dev.php}
当我试图看到http://localhost/web/我收到错误时:
PHP致命错误:在第2行的../App/config/route.php中找不到类'App\Controller\IndexController'
以下是相关文件:
index_dev.php
<?php
require_once __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../App/config/dev.php';
$app = require __DIR__.'/../App/app.php';
$app->run();
?>
Run Code Online (Sandbox Code Playgroud)
app.php
<?php
use Silex\Application;
use Silex\Provider\TwigServiceProvider;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Application();
require __DIR__.'/config/route.php';
return $app;
?>
Run Code Online (Sandbox Code Playgroud)
route.php
<?php
$app->mount('/', new App\Controller\IndexController());
?>
Run Code Online (Sandbox Code Playgroud)
IndexController.php
<?php
namespace App\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
class IndexController implements ControllerProviderInterface {
public function index(Application $app) {
return phpinfo();
}
public function connect(Application $app) {
$controllers = $app['controllers_factory'];
$app->get('/', 'App\Controller\IndexController::index');
return $controllers;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
composer.json
{
"require": {
"silex/silex": "1.0.*"
},
"minimum-stability": "dev"
}
Run Code Online (Sandbox Code Playgroud)
dev*_*ler 11
您缺少自动加载器选项composer.json:
"autoload": { "psr-0": { "App": "./" } }
Run Code Online (Sandbox Code Playgroud)