I tried to start the tutorial at the rest example (haste makes waste). I just added what I thought was needed to establish a route with some echo statments to make sure I was getting there.
<?php
$app = new \Phalcon\Mvc\Micro();
//define the routes here
//Retrieves all robots
$app->get('/api/robots', function() {
});
//Searches for robots with $name in their name
$app->get('/api/robots/search/{name}', function($name) {
});
//Retrieves robots based on primary key
$app->get('/api/robots/{id:[0-9]+}', function($id) {
});
//Adds a new robot
$app->post('/api/robots', function() {
});
//Updates robots based on primary key
$app->put('/api/robots/{id:[0-9]+}', function() {
});
//Deletes robots based on primary key
$app->delete('/api/robots/{id:[0-9]+}', function() {
});
$app->handle();
// Use Loader() to autoload our model
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
__DIR__ . '/models/'
))->register();
// echo "dir is ".__DIR__."<br />";exit;
$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" => "asimov",
"password" => "zeroth",
"dbname" => "robotics"
));
});
//Create and bind the DI to the application
$app = new \Phalcon\Mvc\Micro($di);
//Retrieves all robots
$app->get('/api/robots', function() use ($app) {
echo "got here OK <after get call br />";
$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);
});
echo "got here OK on exit;<br />\n";