Well, I don’t have any obvious solution.
First thing, I’d make sure whether the route works at all.
The simplest thing would be to change getGanttData
to this (echo text message and immediately exit the script)
function getGanttData($request, $response, $args) {
echo "HI!";
die;
}
Then open the data url in the browser.
If I’m not mistaken you use a local domain, so you can access the following:
http://slim.io/data
If nothing appears on the screen - you’ll know there is something wrong with the route.
If you’ll see the text - it would mean the issue with getGanttData
function.
I think it’s the latter since otherwise, you’d either have had 404 error or some other pages result, in case the request is captured by a different route.
To do a quick check of that, you can enable php error reporting and add some echo calls to getGanttData - just add messages after every important step of the method:
<?php
// ! important
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// ! important
function getConnection()
{
return new PDO("mysql:host=localhost;dbname=gantt", "root", "", [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
}
function getGanttData($request, $response, $args) {
echo "enter the method<br>"; // !!!
ob_flush(); // !!!
$db = getConnection();
echo "create connection<br>"; // !!!
ob_flush(); // !!!
$result = [
"data" => [],
"links" => []
];
foreach($db->query("SELECT * FROM gantt_tasks ORDER BY sortorder ASC") as $row){
$row["open"] = true;
array_push($result["data"], $row);
}
echo "select tasks<br>"; // !!!
ob_flush(); // !!!
///...
then open the action url in the browser again and check what is displayed
http://slim.io/data
Do you see all messages, or only some messages (it will give you a clue where the code fails with an error), or do you see no messages at all?