Issue
I follow a tutorial for SlimFramwork and I try to route through some pages that I defined. I have this index.php file from which I run:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
$app = new \Slim\App;
require_once('../app/api/books.php');
$app->run();
?>
and this file books.php which is my page:
<?php
$app->get('/api/books', function() {
echo "Welcome to books";
});
?>
This is my folder structure:
I run this on localhost with wamp using this link:
localhost:8082/myslimsite/app/api/books
I got my localhost on port 8082, my php version is 7.0.10
This are my errors
I try to find on the internet solution but nothing works, something that I found and tried was:
1 - For books to use ($app) like this:
<?php
$app->get('/api/books', function() {
echo "Welcome to books";
});
?>
2 - In books to use the file with the class that have $app variable
require '../vendor/autoload.php';
$app = new \Slim\App;
Solution
Your route is not correct You must navigate first to index.php then to your route
IF your server home page is index.php in the public folder You will only navigate to your route url directory NOT to the path for This file Otherwise you must navigate to public/Your-Route-Url
So Navigate to
localhost:8082/myslimsite/public/api/books
This will Work correctly
Answered By - Ramy hakam
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.