Hi,
I am testing the REST api code from here. https://docs.phalcon.io/en/latest/reference/tutorial-rest.html. But every time i run the code, i get "Sorry!, API not found." from notFound. Here is the code:
$di = new \Phalcon\DI\FactoryDefault();
//Set up the database service
$di->set('db', function(){
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => "localhost",
"username" => "****",
"password" => "****",
"dbname" => "*****"
));
});
//Create and bind the DI to the application
$app = new \Phalcon\Mvc\Micro($di);
//Retrieves all robots
$app->get('/phalcon/api/robots', function() use ($app) {
echo "<h1>Welcome!</h1>";
$phql = "SELECT * FROM Robots ORDER BY name";
$robots = $app->modelsManager->executeQuery($phql);
$data = array();
foreach ($robots as $robot) {
$data[] = array(
'id' => $robot->id,
'name' => $robot->name,
);
}
echo json_encode($data);
});
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo 'Sorry! API not found.';
});
$app->handle();
And then access it via: https://localhost/phalcon/api/robots Not sure, what i am doing wrong here.
Phalcon v 1.2.4 PHP 5.3.17
Any thoughts? Thanks