Change the layout for 404 page #2604

zfbot opened this Issue Sep 28, 2012 · 16 comments


None yet
10 participants

zfbot commented Sep 28, 2012

Jira Information

Original Issue:ZF2-579
Issue Type:New Feature
Reporter:Michael Ben-Nes


I couldn't change the layout ( layout/layout ) to something different from the default through module.config.php

Currently we have:

'not_found_template' => 'error/404',

I suggest adding:

'not_found_layout' => 'whatever',

zfbot commented Sep 28, 2012

This issue was ported from the ZF2 Jira Issue Tracker at

Known GitHub users mentioned in the original message or comment:

HarryR commented Oct 1, 2012

This can be implemented in Module.php pretty easily.

Although it would be very nice to provide not_found_layout and exception_layout attributes to view_manager.

function onBootstrap(EventInterface $e) {
  $app = $e->getApplication();
  $evt = $app->getEventManager();
  $evt->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this,'onDispatchError'), 100);    

function onDispatchError(MvcEvent $e) {
  $vm = $e->getViewModel();

weierophinney commented Oct 1, 2012

I agree with @HarryR -- this is something that can be easily achieved with application-specific listeners at this time. While we could add more attributes to the view_manager, at some point, we have to consider how often they will be used, vs the effort of maintaining them.


mbn18 commented Oct 1, 2012

The mentioned solution (which I use) is ok considering that ZF2 has just born.
I do think layout control using config file is much more elegant and intuitive.

balavec commented Oct 17, 2012

Also suggest something like that ... would be nice.

An issue I'm having with this solution, is that if the 404 is a result of AbstractActionController's createHttpNotFoundModel from the notFoundAction, it is dispatched as a MvcEvent::EVENT_DISPATCH and not MvcEvent::EVENT_DISPATCH_ERROR
It seems that not all 404 errors are considered EVENT_DISPATCH_ERROR


ThaDafinser commented Jul 16, 2013

@HarryR to catch all 404 and errors you need to extend your event handler, because for example the "error-router-no-match" will not be called.

@SlashBin maybe this works for you too?

    public function onBootstrap (EventInterface $event)
        $eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_DISPATCH, array($this, 'onDispatchError'), -100);
        $eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'onDispatchError'), -100);
        $eventManager->getSharedManager()->attach('*', MvcEvent::EVENT_RENDER_ERROR, array(
        ), - 100);

     public function onDispatchError(MvcEvent $event){
        $response = $event->getResponse();
        if ($response->getStatusCode() == 404) {
            //DO SOMETHING
        } elseif($response->getStatusCode() == 500){
            //DO SOMETHING else?



ThaDafinser commented Jul 16, 2013

Maybe pay a bit attention, that the layout is already in the view you have to replace it!

HarryR commented Jul 17, 2013


In short - I ditched ZF2 shortly after writing that, though I did spend some time to catch-up with ZF2 last month in my opinion it really hasn't changed.

The problems remain:

  • I find it completely unintuitive, partly a matter of taste and partly because everything seems so inelegant.
  • Slow is an understatement.
  • Everything gets in my way when trying to "Get Shit Done(tm)", learning curve? Naw... that aint it.

To give you a comparison of what Django does:

That kinda stuff makes me happy, it's there - it just works - it's superbly documented with no ambiguity and overall is very elegant.


ThaDafinser commented Jul 18, 2013

@HarryR it always depends on your needs. If you're fine with Django - stuck with it😃 , i'm very happy with ZF2

But about the "problems":

  • it's different yes, but not inelegant (you are just not used to it...i've also don't liked it at the beginnined, but after some time it's great!)
  • ZF2 is fast - not a hello world, but a real application
  • Learning curve - was also high to me, but that is because of the (great) new concepts which make the framework and your project more flexible, maintainable and faster (real modules, events, services, better mvc, ....)

HarryR commented Jul 18, 2013

I've heard all the 'you are just not used to it' and 'learning curve' arguments for ZF2 time and time again from people in denial, comparatively speaking JEE6 is exceptional - the widespread standardisation on some very well thought out annotations made so many things much easier to express and intuitively it 'just makes sense'.

The ZF2 learning curve is simply because it isn't intuitive until you remember the really weird ways that it overcomplicates the simplest of things; and even then it can be a constant fight digging through the documentation and framework internals to achieve anything.

I try and use the right tool for the job, Django works well, so does Bottle and Flask, GWT, straight up JEE6, Laravel and plain old PHP... they all save time and aren't things that I have to fight to get working. Why is ZF2 different?


Maks3w commented Jul 18, 2013

Sorry by the interruption but I think that this thread is not the best place for this kind of conversation. Feel free to talk in the IRC or in the Mailing list

HarryR commented Jul 18, 2013

I dunno man, on IRC they have a propensity to ban people who try & have a rational discussion about these kinda things.


weierophinney commented Jul 18, 2013

@HarryR Please keep it civil; making accusations without context is not helpful.

If you could provide a list of specific issues you've had, and, better, suggested improvements, and post that to the mailing list, I'd be quite thrilled. I hear comments of "it's hard," "it's bulky," and "too much boilerplate," but I'm not getting anything actionable -- what specifically is hard? what do you find hard about it? what could make it easier? what boilerplate do you feel is impeding productivity? how could it be simplified? etc.

Again, though, post it to the mailing list (directions for subscribing can be found at; comments on a closed issue are difficult to surface and don't invite discussion amongst the larger community.


joshribakoff commented Sep 24, 2013

+1 on setting the layout from config file for me

+1 on setting the layout from config file from me too

@jessiegreen jessiegreen referenced this issue in EvanDotPro/EdpModuleLayouts Mar 22, 2014


Not Found Layout #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment