Skip to content

Instantly share code, notes, and snippets.

@juriansluiman
Last active August 29, 2015 13:56
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 juriansluiman/9051103 to your computer and use it in GitHub Desktop.
Save juriansluiman/9051103 to your computer and use it in GitHub Desktop.
Return response on route
<?php
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap($e)
{
$app = $e->getApplication();
$sl = $app->getServiceManager();
$em = $app->getEventManager();
$em->attach(MvcEvent::EVENT_ROUTE, function($e) use ($sl) {
$connection = $sl->get('My-Database-Connection');
$result = $connection->test();
if (false === $result) {
$response = $e->getResponse();
$response->setStatusCode(500);
$response->setContent('Ooops!');
return $response;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment