[英]Route.php can't find controller class I created
我正在嘗試構建一個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();
?>
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;
?>
route.php
<?php
$app->mount('/', new App\Controller\IndexController());
?>
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;
}
}
?>
composer.json
{
"require": {
"silex/silex": "1.0.*"
},
"minimum-stability": "dev"
}
您在composer.json
中缺少自動加載器選項:
"autoload": { "psr-0": { "App": "./" } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.