I need to use the Phalcon\Mvc\Micro
REST features in a non-micro application. I tried the following code:
<?php
class ApiController extends Phalcon\Mvc\Controller
{
public function postAction()
{
$app = new Phalcon\Mvc\Micro();
$app->setDI($this->di);
$app->get('/api/post', function ($id=null) {
echo "<h1>GET $id!</h1>";
});
$app->post('/api/post', function ($id=null) {
echo "<h1>POST $id!</h1>";
});
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo 'This is crazy, but this page was not found!';
});
$app->handle();
}
}
Is the above code the best practice?