public function attach(EventCollection $events)
{
$this->listeners[] = $events->attach('dispatch.error', array($this, 'renderError'));
- $this->listeners[] = $events->attach('dispatch', array($this, 'render404'), -80);
- $this->listeners[] = $events->attach('dispatch', array($this, 'renderLayout'), -1000);
+ $this->listeners[] = $events->attach('dispatch', array($this, 'render404'), -1000);
+ $this->listeners[] = $events->attach('dispatch', array($this, 'renderLayout'), -80);
}
public function detach(EventCollection $events)
public function registerStaticListeners(StaticEventCollection $events, $locator)
{
- $ident = 'Application\Controller\PageController';
- $handler = $events->attach($ident, 'dispatch', array($this, 'renderPageController'), -50);
- $this->staticListeners[] = array($ident, $handler);
-
$ident = 'Zend\Mvc\Controller\ActionController';
$handler = $events->attach($ident, 'dispatch', array($this, 'renderView'), -50);
$this->staticListeners[] = array($ident, $handler);
}
}
- public function renderPageController(MvcEvent $e)
- {
- $page = $e->getResult();
- if ($page instanceof Response) {
- return;
- }
-
- $response = $e->getResponse();
- if ($response->isNotFound()) {
- return;
- }
-
- $routeMatch = $e->getRouteMatch();
-
- if (!$routeMatch) {
- $page = '404';
- } else {
- $page = $routeMatch->getParam('action', '404');
- }
-
- if ($page == '404') {
- $response->setStatusCode(404);
- }
-
- $script = 'error/' . $page . '.phtml';
-
- // Action content
- $content = $this->view->render($script);
- $e->setResult($content);
-
- return $this->renderLayout($e);
- }
-
public function renderView(MvcEvent $e)
{
$response = $e->getResponse();
$content = $this->view->render($script, $vars);
- $e->setResult($content);
+ $e->setParam('content', $content);
return $content;
}
return $response;
}
- $footer = $e->getParam('footer', false);
- $vars = array('footer' => $footer);
+ $vars = $e->getResult();
+ if (is_scalar($vars)) {
+ $vars = array('content' => $vars);
+ } elseif (is_object($vars) && !$vars instanceof ArrayAccess) {
+ $vars = (array) $vars;
+ }
if (false !== ($contentParam = $e->getParam('content', false))) {
$vars['content'] = $contentParam;
- } else {
- $vars['content'] = $e->getResult();
}
$layout = $this->view->render($this->layout, $vars);
public function renderError(MvcEvent $e)
{
$error = $e->getError();
- $app = $e->getTarget();
$response = $e->getResponse();
if (!$response) {
$response = new Response();
case Application::ERROR_EXCEPTION:
default:
- $exception = $e->getParam('exception');
$vars = array(
'message' => 'An error occurred during execution; please try again later.',
'exception' => $e->getParam('exception'),