4

我正在尝试构建一个 silex 应用程序。我的文件结构是:

根/
    /应用程序/
        /Controller/{IndexController.php}
        /Config/{dev.php,prod.php,route.php}
    /小贩
    /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();

?>

应用程序.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;

?>

路由.php

<?php

$app->mount('/', new App\Controller\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;
  }

}

?>

作曲家.json

{
    "require": {
        "silex/silex": "1.0.*"
    },
    "minimum-stability": "dev"
}
4

1 回答 1

11

您在以下位置缺少 autoloder 选项composer.json

"autoload": { "psr-0": { "App": "./" } }
于 2012-11-02T18:55:11.713 回答