1

How can I use composer autoloader to load slim? I have it a go below,

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();

error:

Fatal error: Class 'Slim\Slim' not found in C:...

Any ideas what have I missed?

Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72
Run
  • 54,938
  • 169
  • 450
  • 748

2 Answers2

3

You can just use ...

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

http://docs.slimframework.com/

cmorrissey
  • 8,493
  • 2
  • 23
  • 27
  • 1
    Although implied he also needs to run `composer install` to install it... then the `vendor/autoload.php` will work correctly. Also at that point he wont need to use `\Slim\Slim::registerAutoloader()`. – prodigitalson Jan 07 '15 at 20:19
1

If you prefer to keep slim under ext (as you mentioned here Slim framework - How to autoload Slim/Slim.php instead of using require?) instead of using it as a composer package, I believe this will work:

{
    "autoload": {
        "psr-0": {
            "": "ext/"
        }
    }
}
Community
  • 1
  • 1
khartnett
  • 831
  • 4
  • 14