Slim Framework PHP Routes

Asked

Viewed 592 times

6

Hello folks I’m having trouble using the Slim framework... when I try to access via get the root "/" I can normal, but when I try to access other methods like "/hello" it simply n goes, error " Not Found

The requested URL /slim/clients was not found on this server." not even with the demo this error persists follows my code ...

    <?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->response()->header('Content-Type', 'application/json;charset=utf-8');


$app->get('/', function () {
echo "SlimProdutos";
});

$app->get('/hello', function (){
    echo "Ola";
});


$app->run();

?> 

follows the . htaccess

RewriteEngine On
#RewriteBase /var/www/slim

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

inserir a descrição da imagem aqui

  • Let your htaccess similar to Slim’s, and put in Rewritebase the name of the folder you placed it RewriteBase /slim/. Let me know the result.

  • Did Guilherme manage to solve?? I also have the same problem.

1 answer

2

Good morning.

I don’t have much experience with Slim, but the way I’ve done and it’s worked:

$app->get('/hello', function() use ($app) {
 ...
}

My . htaccess, it’s like this:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

I hope I’ve helped.

  • It worked!! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.