Skip to content
Advertisement

Slim Php not recognizing gets

I am just starting to work with Slim PHP. What could be the reason that get is not recognized on server?

This route works: it returns required text https://mywebsite/back/public This route doesn’t work (Not Found): https://mywebsite/back/public/countries

I have just installed slim framework and added new index.php file.

<?php
    require '../vendor/autoload.php';


    $app = new SlimApp();

    $app->get('/', function($request, $response, $arg) {
        $response->write("This route works");
    });

    $app->get('/countries', function($request, $response, $arg) {
        $response->write("This route doesnt");
    });



    $app->run();

?>

Advertisement

Answer

What version are you using? If you are using version 4, you need to set the basePath.

$app->setBasePath('/back/public');

Also enable mod_rewrite and configure your .htaccess file.

I recommend you check this project on github slimphp/Slim-Skeleton. This is a boilerplate code for Slim 4 applications.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement