Reputation: 125
After running "composer require slim/csrf" to download the csrf dependency files My index page is like this:
session_start();
require '/Slim/Slim.php';
require '.../vendor/autoload.php';
//register slim auto-loader
\Slim\Slim::registerAutoloader();
//load Twig files after loading Slim
require '../Views/Twig.php';
//initialize Slim to use Twig
$app = new \Slim\Slim(array('view' => new Slim\Views\Twig()));
//add CSRF middleware
$app->add(new \Slim\Csrf\Guard);
//GET route - homepage
$app->get('/', function() use($app) {
$app->render("index.php");
});
$app->run();
But when I load it in the browser, I get this error
Catchable fatal error: Argument 1 passed to Slim\Slim::add() must be an instance of Slim\Middleware, instance of Slim\Csrf\Guard given, called in C:my-root-folder\index.php on line 27 and defined in C:my-root-folder\Slim\Slim.php on line 1269
Kindly help, I'm a bit new to slimphp
Upvotes: 0
Views: 969
Reputation: 20397
You seem to be trying to use Slim 3 middleware with Slim 2. To use \Slim\Csrf\Guard
you should be using Slim 3 instead.
Upvotes: 1