Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- try {
- /**
- * Read the configuration
- */
- $config = include __DIR__ . '/../config/config.php';
- $loader = new Loader();
- $loader->registerNamespaces(array(
- 'Libs' => __DIR__ . '/../library/',
- ));
- $loader->register();
- /**
- * Include services
- */
- require __DIR__ . '/../config/services.php';
- /**
- * Handle the request
- */
- $application = new Application();
- /**
- * Assign the DI
- * @var Phalcon\DI\FactoryDefault $di
- */
- $application->setDI($di);
- /**
- * Include modules
- */
- require __DIR__ . '/../config/modules.php';
- echo $application->handle()->getContent();
- } catch (Phalcon\Exception $e) {
- // remove view contents from buffer
- ob_clean();
- $errorCode = 500;
- $errorView = __DIR__ . '/../apps/commons/views/error.phtml';
- switch (true) {
- // 401 UNAUTHORIZED
- case $e->getCode() == 401:
- $errorCode = 401;
- break;
- // 403 FORBIDDEN
- case $e->getCode() == 403:
- $errorCode = 403;
- break;
- // 404 NOT FOUND
- case $e->getCode() == 404:
- case ($e instanceof Phalcon\Mvc\View\Exception):
- case ($e instanceof Phalcon\Mvc\Dispatcher\Exception):
- case ($e instanceof Phalcon\DI\Exception):
- $errorCode = 404;
- break;
- }
- // Get error view contents. Since we are including the view
- // file here you can use PHP and local vars inside the error view.
- ob_start();
- include_once $errorView;
- $contents = ob_get_contents();
- ob_end_clean();
- // send view to header
- $di->getShared('response')
- ->resetHeaders()
- ->setStatusCode($errorCode, null)
- ->setContent($contents)
- ->send();
- } catch (PDOException $e){
- echo $e->getMessage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement