Slim framework php installation giving error in index.php

Viewed 431

I am new to Slim PHP. I read documentation and installed SLIM PHP in my laptop. Here is how I have installed:

  1. Installed composer
  2. composer require slim/slim:"4.*"
  3. composer require slim/psr7

I have followed these steps from http://www.slimframework.com/docs/v4/start/installation.html

And when I created index.php in root directory and pasted the hello world code, It's giving me errors in browser

Fatal error: Uncaught Slim\Exception\HttpNotFoundException: Not found. in E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php:93 Stack trace: #0 E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\Routing\RouteRunner.php(72): Slim\Middleware\RoutingMiddleware->performRouting(Object(Slim\Psr7\Request)) #1 E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\MiddlewareDispatcher.php(81): Slim\Routing\RouteRunner->handle(Object(Slim\Psr7\Request)) #2 E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\App.php(215): Slim\MiddlewareDispatcher->handle(Object(Slim\Psr7\Request)) #3 E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\App.php(199): Slim\App->handle(Object(Slim\Psr7\Request)) #4 E:\xampp\htdocs\zain\hadithsapi\index.php(15): Slim\App->run() #5 {main} thrown in E:\xampp\htdocs\zain\hadithsapi\vendor\slim\slim\Slim\Middleware\RoutingMiddleware.php on line 93

Here is the index.php code:

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;

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

$app = AppFactory::create();

$app->get('/', function ($request, $response, $args) {
    $response->getBody()->write("Hello world!");
    return $response;
});

$app->run();

Can you please tell me, why I am getting these errors. Please help me

1 Answers
Related