Created
September 13, 2012 17:57
-
-
Save nesbert/3716234 to your computer and use it in GitHub Desktop.
Phalcon WIP API index.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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