du9698 2015-06-08 18:07
浏览 42
已采纳

Silex找不到控制器类

project directory structure

/composer.json
/web/index.php
/app/controller/IndexController.php 

composer.json

{
  "require" : {
    "silex/silex": "*"
  },
  "autoload": {
    "psr-0": {
            "": "./"
        }
  }
}

index.php

require_once __DIR__.'/../vendor/autoload.php';

use Silex\Application;

$app = new Application();
$app['debug'] = true;

$app->get('/', 'App\\Controller\\IndexController::getIndex');

$app->run();

IndexController.php

namespace App\Controller;

use Silex\Application;

class IndexController
{
    public function getIndex(Application $app)
    {
        return "You got the index, congrats!";
    }
}

Whenever I

cd web/
php -S localhost:8080
curl http://localhost:8080

from the project root I get the the following exception

InvalidArgumentException in ControllerResolver.php line 153:
Class "App\Controller\IndexController" does not exist.
in ControllerResolver.php line 153
at ControllerResolver->createController('App\Controller\IndexController::getIndex') in ControllerResolver.php line 80
at ControllerResolver->getController(object(Request)) in HttpKernel.php line 135
at HttpKernel->handleRaw(object(Request), '1') in HttpKernel.php line 68
at HttpKernel->handle(object(Request), '1', true) in Application.php line 581
at Application->handle(object(Request)) in Application.php line 558
at Application->run() in index.php line 12

Which makes no sense to me. The program actually runs just fine locally on my macbook but when I deploy it to my ubuntu VPS I get the above exception even though the code being run in both environments is identical. Why can't Silex find my controller?

  • 写回答

3条回答 默认 最新

  • douyannuo7733 2015-06-08 18:32
    关注

    It was a capitalization issue. My macbook has a case-insensitive filesystem and my Linux VPS has a case-sensitive filesystem so when deploying to the VPS I had to capitalize the directories in my project so that Silex could correctly resolve the controllers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入