Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:24:36+00:00 2026-06-05T11:24:36+00:00

Im currently building a controller from my Zend MVC application which would only be

  • 0

Im currently building a controller from my Zend MVC application which would only be used as json service to populate the page. I want to restrict the users to use only GET method to access this end point(for some security reasons).

I followed this post _forward() in Zend does not work? but could not get working.

I am using the preDispatch to detect the non-get requests and would like to forward to errorAction in the same controller. My code looks likes this,

public function preDispatch(){
    $this->_helper->layout()->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
    //Restrict this Controller access to Http GET method
    if(!($this->getRequest()->isGet())){
        return $this->_forward('error');
    }
}

public function errorAction(){
    $this->getResponse()->setHttpResponseCode(501);
    echo "Requested Method is not Implemented";
}

When I test the page with a post request, it throws

PHP Fatal error: Maximum execution time of 30 seconds exceeded

I got it working with

$this->_redirect("service/error");

Wondering if it is the only/best way to handle this situation.

Any help would be really appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:24:39+00:00Added an answer on June 5, 2026 at 11:24 am

    The reason that calling _forward doesn’t work is because the request method doesn’t change so you end up in an infinite loop trying to forward to the error action since the request is always POST.

    _forward works by modifying the module, controller, and action that will be called when the request is dispatched, _redirect actually returns a 302 redirect and results in an additional HTTP request by the browser.

    Either method is okay, but I’d prefer to go with _forward since it won’t require an additional HTTP request (but you still guarantee the POST request is denied).

    This code should work for you:

        if(!($this->getRequest()->isGet())){
            // change the request method - this only changes internally
            $_SERVER['REQUEST_METHOD'] = 'GET';
    
            // forward the request to the error action - preDispatch is called again
            $this->_forward('error');
    
            // This is an alternate to using _forward, but is virtually the same
            // You still need to override $_SERVER['REQUEST_METHOD'] to do this
            $this->getRequest()
                 ->setActionName('error')
                 ->setDispatched(false);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
I'm building an application based on the Utility template from Xcode, to which I
I'm building a ASP MVC application. When I request a route to a controller,
I'm currently building a web application (utilizing Zend Framework) and have gotten some of
I am currently building an making my new website. It uses one page and
I am currently building an application using Tomcat, Spring and JAVA. I am using
I'm building an iPhone app which gets updates from the web at regular time
I am building an application in Zend Framework. My model is made up of
I'm building an iphone application which involves a video player,audio player and more in
I'm building an ASP.Net MVC 2 application with a component architecture. There are two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.