Skip to content

Instantly share code, notes, and snippets.

@nesbert
Created September 13, 2012 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nesbert/3716234 to your computer and use it in GitHub Desktop.
Save nesbert/3716234 to your computer and use it in GitHub Desktop.
Phalcon WIP API index.php
<?php
$di = new \Phalcon\DI\FactoryDefault();
$response = new \Phalcon\Http\Response();
$response->setContentType('application/json', 'utf-8');
$di->set('response', $response);
$app = new Phalcon\Mvc\Micro();
$app->setDI($di);
try {
// default route
$app->get('/', function() {
echo json_encode(array('status' => 'OK', 'messages' => 'hello world'));
});
// default not found
$app->notFound(function() use ($app) {
$app->getSharedService('response')
->setStatusCode(404, null);
echo json_encode(array('status' => 'ERROR', 'messages' => 'resource not found'));
});
} catch (\Exception $e) {
if ($e->getCode()) {
$response->setStatusCode($e->getCode(), null);
} else {
$response->setStatusCode(500, null);
}
}
$app->handle();
$response->send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment