Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend 2: How to throw a 404 error from controller

I want to throw a '404 Page not found' error from my controller. How can I do that?

I use Zend Framework 2 not 1.

like image 642
Paul Moldovan Avatar asked Apr 12 '13 09:04

Paul Moldovan


2 Answers

class IndexController extends AbstractActionController
{
    public function previewAction ()
    {
        return $this->notFoundAction ();
    }
}
like image 64
akond Avatar answered Sep 20 '22 18:09

akond


Just try with:

$this->getResponse()->setStatusCode(404);
return; 

in your controller's action method.

like image 42
hsz Avatar answered Sep 18 '22 18:09

hsz