Skip to content
This repository

Change the layout for 404 page #2604

Closed
zfbot opened this Issue · 16 comments

10 participants

Zend Framework DevTeam Harry Matthew Weier O'Phinney Michael Ben-Nes Robert SlashBin Martin Keckeis Maks Josh Ribakoff Damijan Cavar
Zend Framework DevTeam
Owner

Jira Information

Original Issue: ZF2-579
Issue Type: New Feature
Reporter: Michael Ben-Nes
Created: 09/21/12
Assignee: weierophinney
Components: Zend\View

Description

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',
Zend Framework DevTeam
Owner

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-579

Known GitHub users mentioned in the original message or comment:
@weierophinney

Harry

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();
  $vm->setTemplate('layout/blank');
}
Matthew Weier O'Phinney

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.

Michael Ben-Nes

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.

Robert

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

SlashBin

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

Martin Keckeis

@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(
            $this,
            'onDispatchError'
        ), - 100);
    }

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

//EDIT updated EVENT_RENDER_ERROR

Martin Keckeis

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

Harry
HarryR commented

@ThaDafinser

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: https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views

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

Martin Keckeis

@HarryR it always depends on your needs. If you're fine with Django - stuck with it:smiley: , 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, ....)
Harry
HarryR commented

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?

Maks
Collaborator
Maks3w commented

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

Harry
HarryR commented

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

Matthew Weier O'Phinney
Owner

@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 http://framework.zend.com/archives/subscribe/); comments on a closed issue are difficult to surface and don't invite discussion amongst the larger community.

Josh Ribakoff

+1 on setting the layout from config file for me

Damijan Cavar

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

Jessie Green jessiegreen referenced this issue in EvanDotPro/EdpModuleLayouts
Open

Not Found Layout #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.