skip to Main Content

I’m creating an web app, and I can’t move because of Slim 4. It’s showing up this error:

Fatal error: Uncaught SlimExceptionHttpNotFoundException: Not found. in C:xampphtdocsprojectfolderappvendorslimslimSlimMiddlewareRoutingMiddleware.php:91 Stack trace: #0 C:xampphtdocsprojectfolderappvendorslimslimSlimRoutingRouteRunner.php(72): SlimMiddlewareRoutingMiddleware->performRouting(Object(SlimPsr7Request)) #1 C:xampphtdocsprojectfolderappvendorslimslimSlimMiddlewareDispatcher.php(81): SlimRoutingRouteRunner->handle(Object(SlimPsr7Request)) #2 C:xampphtdocsprojectfolderappvendorslimslimSlimApp.php(215): SlimMiddlewareDispatcher->handle(Object(SlimPsr7Request)) #3 C:xampphtdocsprojectfolderappvendorslimslimSlimApp.php(199): SlimApp->handle(Object(SlimPsr7Request)) #4 C:xampphtdocsprojectfolderappindex.php(16): SlimApp->run() #5 {main} thrown in C:xampphtdocsprojectfolderappvendorslimslimSlimMiddlewareRoutingMiddleware.php on line 91

I’m using xampp, there is apache server and I thought the problem was there, in .htacces file, but hell no..

here is how it looks

error

I’ve been trying to fix this for more than 4-5 hours, I tried everything I found on google, stackoverflow, Slim’s Github, YouTube.. nothing is working.

.htacces

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSL,L]

My directory

folders

composer.json

json

index.php below:

use PsrHttpMessageResponseInterface as Response;
use PsrHttpMessageServerRequestInterface as Request;
use SlimFactoryAppFactory;

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

$app = AppFactory::create();

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

$app->run();

I do not know what to do anymore, maybe someone can help me and other thousands of people who can’t find the answer, or it will be better idea to move and trying another framework..

2

Answers


  1. I see some possible issues that cause the problem.

    • The vendor/ directory belongs into the project-root directory
    • There is a typo in scr/, it should be src/
    • The index.php (front controller) should be placed in a separate directory, e.g. public/
    • You are running your app in sub-directory of the webservers documentRoot. So you need a second .htaccess file in the project root directory.
    • Then you need to configure the Slim basePath to ‘projectFolder/’ or you use the BasePathMiddleware for this purpose.

    In my blog post Slim Framework Tutorial I explain this all in detail.

    Login or Signup to reply.
  2. Set A URL base path detector for Slim 4.
    Follow steps here https://github.com/selective-php/basepath

    <?php
    
    use PsrHttpMessageResponseInterface as Response;
    use PsrHttpMessageServerRequestInterface as Request;
    use SelectiveBasePathBasePathMiddleware;
    use SlimFactoryAppFactory;
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    $app = AppFactory::create();
    
    // Add Slim routing middleware
    $app->addRoutingMiddleware();
    
    // Set the base path to run the app in a subdirectory.
    // This path is used in urlFor().
    $app->add(new BasePathMiddleware($app));
    
    $app->addErrorMiddleware(true, true, true);
    
    // Define app routes
    $app->get('/', function (Request $request, Response $response) {
        $response->getBody()->write('Hello, World!');
        return $response;
    })->setName('root');
    
    // Run app
    $app->run();
    ?> 
    

    That should work properly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search