Ivaylo
Ivaylo

Reputation: 291

Exceptions in the view are resulting in a white screen in ZF2

I have started to play with the dev version of ZF2 in the current dev-develop branch and since then I am getting white screen on every exception, thrown somewhere in the views.

I have installed the SkeletonApplication to see, if it is something in my application, that was causing it, but same problem appear there too. Downgrading to dev-master solves the problem and I am getting the standard exception dump.

Looking into the zf2 code I think I have found the reason for this. In Zend\Mvc\View\Http\DefaultRenderingStrategy::render() now we have:

public function render(MvcEvent $e)
{
    ......
    try {
        $view->render($viewModel);
    } catch(\Exception $ex) {
        $application = $e->getApplication();
        $events      = $application->getEventManager();
        $e->setError(Application::ERROR_EXCEPTION)
          ->setParam('exception', $ex);
        $events->trigger(MvcEvent::EVENT_RENDER_ERROR, $e);
    }
    return $response;
}

So the Exception is catched, but the response is empty and I have no clue about the cause of the latter.

However another question appears: How is the error handler going to render the exception page, if the error is triggered in the layout? (Like in my case - the navigation helper, which was unable to find the container.) The only possible solution is to have an extra error layout, but this is pointless, since the reason of having a nice exception handling is not present anymore.

So following questions are arising:

  1. How do ZF2 developers plan to solve the issue?
  2. Is there a current workaround (actually commenting out the try { } catch() { } fixes the problem, but is not a good solution)
  3. Since the pull request, which brought the above code, is closed, am I doing anything entirely wrong and am I completely wrong about the way it should work?

Upvotes: 2

Views: 1488

Answers (1)

AlloVince
AlloVince

Reputation: 1655

Check your zf2 config files to make sure you have opened exception display options:

'view_manager' => array(
    'display_not_found_reason' => true,
    'display_exceptions'       => true,
),

Upvotes: -1

Related Questions