Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

added cookbook for set up custom 404 page #81

Merged
merged 5 commits into from
Dec 1, 2015

Conversation

samsonasik
Copy link
Contributor

@weierophinney this is what I can get from your site: https://github.com/weierophinney/mwop.net/blob/master/config/autoload/global.php . Still not sure about using 404 page with WhoopsErrorHandler or TemplatedErrorHandler.

Note:
defining 'error' => true in middleware_pipeline config make it not working. Please let me know if I missed something. Thanks.

}
```

After it, we need to register the middleware into `invokables` type in our service config:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specific to a single container implementation, zend-servicemanager. We should likely either (a) provide setup for multiple containers, or (b) leave container configuration as an exercise for the reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

@weierophinney
Copy link
Member

Note:
defining 'error' => true in middleware_pipeline config make it not working. Please let me know if I missed something. Thanks.

You did. Error middleware in Stratigility and Expressive must have the following signature:

function ($error, ServerRequestInterface $request, ResponseInterface $response, callable $next)

Note the first argument!

The way you have set this up is correct; it's not actually error middleware; it's middleware that you want to intercept if no other middleware has executed by that point, and is indicative of a "not found" situation.

That said, this is only one of several approaches.

The current recommend approach is to use the final handler. The final handler is invoked when the stack is exausted (i.e., no middleware returns a response), and that can then determine if we have a 404 situation. The TemplatedErrorHandler will use a template for rendering the 404 page. This allows us to have something baked into the library for the situation.

The approach you're suggesting here is more suited for custom 404 handling; e.g., you may want to log such requests, or provide suggestions based on the URI for other pages, etc. In those cases, I'd use middleware. For a generic 404 page, however, the final handler approach is easier, and already provided to the user.

So, my suggestions:

  • Per inline comments, either remove the container configuration, or cover other containers as well as zend-servicemanager.
  • Detail why you might want an alternative 404 handler, instead of using the final handler.

@samsonasik
Copy link
Contributor Author

I did The TemplatedErrorHandler example in skeleton, and it shows blank page, even I create a template file under templates/error named 404.php. @weierophinney could you relieve it ? thanks ;)

@weierophinney
Copy link
Member

@samsonasik the 404 condition may be related to #93; looking into that today.

@samsonasik
Copy link
Contributor Author

@weierophinney it works now 👍 , I've updated the wording.

@samsonasik samsonasik changed the title added cookbook for set up 404 page added cookbook for set up custom 404 page Aug 25, 2015
@samsonasik
Copy link
Contributor Author

@weierophinney merge-able now ?

@weierophinney
Copy link
Member

@samsonasik I'm still evaluating.

As noted above, I think the recommendation for 404 pages should be to use one of the final handler implementations we ship. However, I do think it would make sense to have some examples of different types of error handlers.

As an example, on my site, I have an "Unauthorized" error handler that looks to see if the response status has been set to 401 or 403 and/or certain crtieri; in such a case, it then renders a template with a login form and sets the appropriate status. That sort of approach would be a useful example for the cookbook.

@samsonasik
Copy link
Contributor Author

rebased.


```php
$app->pipe($services->get('Application\NotFound'));
$app->run();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick note: the above only works if one of the following criteria are met:

  • You have first called $app->pipeRoutingMiddleware(); or
  • if you pulled the Application instance from the container, and used the ApplicationFactory shipped with Expressive (which ensures the routing middleware has been added to the pipeline).

I'll add that note when merging.

@weierophinney weierophinney added this to the 1.0.0rc3 milestone Dec 1, 2015
@weierophinney weierophinney self-assigned this Dec 1, 2015
@weierophinney weierophinney merged commit b479339 into zendframework:master Dec 1, 2015
weierophinney added a commit that referenced this pull request Dec 1, 2015
added cookbook for set up custom 404 page
weierophinney added a commit that referenced this pull request Dec 1, 2015
- Incorporated the feedback I presented.
- Modified the structure to present the two possible ways to do 404
  handling (either explicitly delegating to error middleware and/or the
  final handler, or generating and returning a 404 response).
weierophinney added a commit that referenced this pull request Dec 1, 2015
weierophinney added a commit that referenced this pull request Dec 1, 2015
weierophinney added a commit that referenced this pull request Dec 1, 2015
@samsonasik samsonasik deleted the cookbook/404 branch December 1, 2015 20:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants