How to redirect to 404 page in zend Framework 2

The Zend framework automatically does this if the user selected route doesn’t exists.
Although in some situations like getting data from database where the route is valid , but response is 404 (row not exits or may be row has been removed), in that case ,where may be we should have to show 404 page.

Here is line of code which will redirect visitor(user) to 404 page, this will trigger the Zend framework 2 ’s RouteNotFoundStrategy.

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

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

DMCA.com Protection Status