Skip to content

How to redirect to 404 page in zend Framework 2

Last updated on December 21, 2022

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

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

$this->getResponse()->setStatusCode(404);
return; 
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments