Composer自动加载器+超薄框架 - 致命错误:找不到类'Slim \ Slim'?

时间:2015-01-07 19:15:39

标签: php composer-php slim autoloader

如何使用composer autoloader加载slim?我把它放在下面,

composer.json:

{
    "autoload": {
        "psr-4": {
            "Vendor\\Namespace\\": ""
        }
    }
}

的index.php:

require dirname(__FILE__).'/vendor/autoload.php';

use \Slim\Slim;

Slim::registerAutoloader();

//Instantiate a Slim application:
$app = new Slim();

//Define a HTTP GET route:
$app->get('/', function () {
    echo "Hello!";
});

$app->get('/hello/:name/', function ($name) {
    echo "Hello, $name";
});

//Run the Slim application:
$app->run();

错误:

  

致命错误:Class' Slim \ Slim'在C中找不到:......

我错过了哪些想法?

2 个答案:

答案 0 :(得分:3)

你可以使用......

{
    "require": {
        "slim/slim": "2.*"
    }
}

http://docs.slimframework.com/

答案 1 :(得分:1)

如果你喜欢在ext(如你在这里提到的Slim framework - How to autoload Slim/Slim.php instead of using require?)中保持苗条而不是将其用作作曲家包,我相信这会有效:

{
    "autoload": {
        "psr-0": {
            "": "ext/"
        }
    }
}