Slim3 Autoload class error


#1

Hi,
I am new to slim framework. I am trying to use slim version3 for rest services.What is the best way to install through composer or manually.If manually means how to load the dependencies and trait files in index.php.

Kindly help me proceed to next step.
This is my index.php code:

<?php require 'Slim/App.php'; $app = new App(); $app->get('/hello/:name', function ($name) { echo "Hello, $name! Welcome to Slim Framework"; }); $app->run(); ?>

Output:
Fatal error: Trait ‘Slim\MiddlewareAwareTrait’ not found in \api\Slim\App.php


#2

It looks like you’re not requiring the autoloader.

<?php

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

$app = new \Slim\App();

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $response->write("Hello " . $args['name']);
});

$app->run();

#3

Thanks for your reply,
I am trying to install slim framework manually.So how to include auto loader file.In that slim framework folder there is no autoloder file.

Please give the steps to install slim framework manually.


#4

Can I ask why?

Save yourself a load of work and use Composer. Then it is just a one line command and your done. Otherwise you will need to download all of the dependencies by hand, extract them, and then create your own autoloader, classmap, etc.