Skip to content

Loading…

Dispatching to a good controller but wrong action triggers a Fatal Error #3186

Closed
wants to merge 1 commit into from

2 participants

@weierophinney weierophinney commented on the diff
library/Zend/Mvc/Controller/AbstractActionController.php
@@ -51,6 +51,9 @@ public function notFoundAction()
$event = $this->getEvent();
$routeMatch = $event->getRouteMatch();
+ if($response instanceof \Zend\Console\Response) {
+ return null;
+ }
$response->setStatusCode(404);
$routeMatch->setParam('action', 'not-found');
@weierophinney Zend Framework member

I think the test is wrong. We still want the route match change; we simply want to not set the status code, unless we have an HTTP response.

Do we want to return a ViewModel ? I can move the routeMatch or conditionally set the status code + return the ViewModel on \Zend\Http\Response. Which one is preferable ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney [#3186] Only set status code if response is HTTP
- Inverted condition from original PR; only set status code if we have
  an HTTP request
819247b
@weierophinney weierophinney added a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3186' into develop
Forward port #3186
497899b
@weierophinney weierophinney added a commit that closed this pull request
@weierophinney weierophinney Merge branch 'hotfix/3186'
Close #3186
c8b8ffb
@ThomasCantonnet

@weierophinney this fix now triggers a different fatal error:

PHP Fatal error: Call to undefined method Zend\View\Model\ViewModel::getResult() in Zend/Mvc/View/Console/DefaultRenderingStrategy.php on line 94

Fix for this is returning a ConsoleModel instead of ViewModel on Console\Response in Zend/Mvc/Controller/AbstractActionController.php. Want me to do another PR?

@weierophinney weierophinney added a commit to weierophinney/zf2 that referenced this pull request
@weierophinney weierophinney Better capabilities surrounding console notFoundAction
- Return a console response for non-HTTP response types; resolves comment noted
  in zendframework/zf2#3186
1682874
@weierophinney
Zend Framework member

@H3DAZ #3254 fixes the issue you saw. :)

@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney [#3186] Only set status code if response is HTTP
- Inverted condition from original PR; only set status code if we have
  an HTTP request
9e1c8c4
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3186'
Close #3186
524228d
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Merge branch 'hotfix/3186' into develop
Forward port #3186
67927b8
@ghost Unknown pushed a commit that referenced this pull request
@weierophinney weierophinney Better capabilities surrounding console notFoundAction
- Return a console response for non-HTTP response types; resolves comment noted
  in zendframework/zf2#3186
c7467b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2012
  1. @ThomasCantonnet

    fix cli issue

    ThomasCantonnet committed
Showing with 3 additions and 0 deletions.
  1. +3 −0 library/Zend/Mvc/Controller/AbstractActionController.php
View
3 library/Zend/Mvc/Controller/AbstractActionController.php
@@ -51,6 +51,9 @@ public function notFoundAction()
$event = $this->getEvent();
$routeMatch = $event->getRouteMatch();
+ if($response instanceof \Zend\Console\Response) {
+ return null;
+ }
$response->setStatusCode(404);
$routeMatch->setParam('action', 'not-found');
@weierophinney Zend Framework member

I think the test is wrong. We still want the route match change; we simply want to not set the status code, unless we have an HTTP response.

Do we want to return a ViewModel ? I can move the routeMatch or conditionally set the status code + return the ViewModel on \Zend\Http\Response. Which one is preferable ?

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.