Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

api - 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();

?>
question from:https://stackoverflow.com/questions/65893167/slim-php-not-recognizing-gets

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...