Last active
August 29, 2015 13:56
-
-
Save juriansluiman/9051103 to your computer and use it in GitHub Desktop.
Return response on route
This file contains 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 | |
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