Okay, so I've finally managed to get my API working in the slim framework on my MAMP localhost with this code in my index.php:
$app = new \Slim\Slim();
$app->get('/people', function() use ($app, $mysqli) {
$testQuery = "SELECT name FROM People";
$results = $mysqli->query($testQuery);
$app->response()->header('Content-Type', 'application/json');
while ($row = $results->fetch_assoc()) {
echo json_encode($row);
}
});
$app->run();
Now, when I go to localhost/index.php/musicians, I get exactly what I expect -- JSON encoded text representing the names on the people table. However, if I just go to localhost, I get text I printed earlier in the index.php file AND a 404 error. Moreover, when I run index.php in the console, I get this error message:
Notice: Undefined index: REQUEST_METHOD in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 123
Notice: Undefined index: REMOTE_ADDR in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 126
Notice: Undefined index: REQUEST_URI in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 143
Notice: Undefined index: REQUEST_URI in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 148
Notice: Undefined index: SERVER_NAME in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 159
Notice: Undefined index: SERVER_PORT in /Applications/MAMP/htdocs/vendor/slim/slim/Slim/Environment.php on line 162
The API is clearly succeeding in creating a RESTful API, but I'm worried about what's going on with index.php and these error messages.