ZF2-228: ActionController#notFoundAction does not set template

Description

With the recent view layer update, problems started with the notFoundAction() in Zend\Mvc\Controller\ActionController. In the ZendSkeletonApplication there is a view for 404 pages (error/404), but with setting the routeMatch action parameter to not-found, the resolver might look for /not-found as well. For example in Foo\Controller\BarController the resolver will look for bar/not-found. Link: https://github.com/zendframework/zf2/…

This happens when a dispatchable controller can be found, but with an action in the route which does not exist. I know this is not a real ZF2 issue for the library code, but merely in combination with ZendSkeletopApplication (and thus also other apps) this can create some serious issues. I did not make a PR as I am unsure how to solve this issue.

Comments

I believe this is now fixed? I checked out ZendSkeletonApplication:master, and 404 error pages work properly now. Could you please confirm if the issue no longer exists?

This bug is still present. It is quite specific, as most 404 pages work (no routematch, no controller from DI, controller is not dispatchable). However, if all these things are true, but an action is invalid, the template is set wrong.

I discussed this also with weierophinney (who made this implementation) and akrabat (who suggested this for the following reason):

{quote} [16:16:05] weierophinney: I'd like to solve this issue, can you give a direction how this can be solved? http://framework.zend.com/issues/browse/ZF2-228 [16:19:33] jurians: well, the "easy" way is to define a template for that controller's "not found" action. :) [16:20:08] weierophinney: yeah, having many not-found.phtml foo/not-found, bar/not-found etc Is that a real solution? [16:20:09] jurians: talk to Akrabat a bit about it -- we went back and forth on that decision before merging. He argued it would be nice to have controller-specific not-found pages. [16:20:50] weierophinney: kk, but should it be possible to override somehow and say: for every not-found I want to use error/404, for examlpe? [16:20:58] s/examlpe/example [16:21:01] jurians: the other possibility is to alter ActionController and RestfulController such that they specify a different template. However, that requires injecting the configured name for the 404 template -- which is a WTF factor as well. [16:21:03] jurians: IMO that injection should be somewhere around Router or within a Mvc\Listener bound to "route" app event. [16:21:23] jurians: for that, you can easily create a listener that alters the view model's template. [16:21:56] Thinkscape: won't work. In this case, the router has a match -- but the controller has decided it doesn't actually know what to do with it. [16:22:04] weierophinney: I think it's a matter of ease of use and documentation for end users. Else it would be a big WTF for users. [16:22:15] But I get it now, so for me personally it's not a real issue [16:22:22] Thinkscape: consider: some-segment/:action -- the action is matched, but the controller decides if it knows what to do. [16:22:25] wasn't it defaulting to index.phtml otherwise? [16:22:37] Akrabat: yes -- that was the change you suggested making. [16:22:50] jurians: we probably should make it easier. It may be something for tooling, however. [16:23:04] yeah - cos an incorrect controller action shouldn't result in index.phtml being rendered [16:23:27] weierophinney: true. With this issue it is documented at least, perhaps later on we find a solution to close this [16:23:41] weierophinney: correct. Then controller could take it on it's head, because there's already some stuff inside it. [16:23:49] Akrabat: you think it is recommended to put a not-found.phtml in every view folder then? [16:23:57] weierophinney: ActionController [16:24:17] jurians: I think index.phtml is a major wtf if you ask for index/test [16:24:51] true, but (for SkeletonApplication at least) error/404 is even better as template. However, then you hard-code this in the library, not really nice [16:24:55] I can see the benefit of a single one in Application, but I never got that far in my thinking. I just didn't want my album/index.phtml rendered when I went to album/asdfasdf {quote}

I just came accross this situation and created a topic in the Nabble's Zend Community so that Jurians replied and forwarded a link to this Issue's page. Well... Yet, as I can see this is a bug. However, a new question about this notFoundAction arises. The RFC 2616 says that 404 is a Not-found page status message. So what the real need for both 404 and Not-found pages in a Zend application once both mean the very same thing? In my point of view it is redundant resource and effort.

By just looking at code it seems to solve the issue, I will pull the commit and test

PR Merged