简体   繁体   English

Route.php找不到我创建的控制器类

[英]Route.php can't find controller class I created

I'm trying to build a silex application. 我正在尝试构建一个silex应用程序。 My file structure is: 我的文件结构是:

ROOT/
    /App/
        /Controller/{IndexController.php}
        /Config/{dev.php,prod.php,route.php}
    /vendor
    /web/{index.php, index_dev.php}

When I'm trying to see http://localhost/web/ I get error: 当我试图看到http://localhost/web/我得到错误:

PHP Fatal error: Class 'App\\Controller\\IndexController' not found in ../App/config/route.php on line 2 PHP致命错误:在第2行的../App/config/route.php中找不到类'App \\ Controller \\ IndexController'

Here are the relevant files: 以下是相关文件:

index_dev.php 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 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 route.php

<?php

$app->mount('/', new App\Controller\IndexController());

?>

IndexController.php 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 composer.json

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

您在composer.json中缺少自动加载器选项:

"autoload": { "psr-0": { "App": "./" } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM