Question

I have just started using Slim framework (http://www.slimframework.com/); I have downloaded the zip file from the same site which has some examples and to test it I tried localhost/proj1 and it works but when I try localhost/proj1/index.php/delete it keeps me giving me 404 error, although it is supposed to echo out "This is a DELETE route", if I'm right!

$app->delete(
    '/delete',
    function () {
        echo 'This is a DELETE route';
    }
);

am I doing something wrong?

.htaccess:

RewriteEngine On

# Some hosts may require you to use the `RewriteBase` directive.
# If you need to use the `RewriteBase` directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Was it helpful?

Solution

You should be pointing your browser to:-

localhost/proj1/delete

And your code should be:-

$app->get('/delete',
 function(){
        echo 'This is a DELETE route';
    }
);

As your browser will be sending a 'get' request, not a 'delete' request. Your original code would work if your browser sent a 'delete' request, but it can't. See this answer to find out why.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top