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 3239726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:00:13+00:00 2026-05-17T18:00:13+00:00

During Zend_Controller_Action::init() , is there a way to cancel the action (so it won’t

  • 0

During Zend_Controller_Action::init(), is there a way to cancel the action (so it won’t be called)?

<?php
class JsonApiController extends Zend_Controller_Action {
    function init()
    {
        // try JSON decoding the raw request body
        if ($jsonDecodingFailed) {
            echo '{"error":"invalid JSON"}';
            $this->_cancelAction(); // something like this exist?
        }
    }
}

My current workaround is to make an empty nullAction() method and call $this->_forward('null') to forward to it.

  • 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-05-17T18:00:14+00:00Added an answer on May 17, 2026 at 6:00 pm

    Theres nothing wrong in using $this->_forward() inside the init() (if the method you want to forward to is inside the same controller as the init()), this will simply change the request object’s controller / action (overwrite what has been set via the router).

    An alternative to this would be to create a Zend_Controller_Plugin as it looks like you are handling unexpected errors.
    Have a look at the Zend_Controller_Plugin_ErrorHandler implementation.
    So instead of forwarding to another action you would throw an exception, and have your custom plugin check in postDispatch() if the response contains eny expections, and if it does simply edit the current Request object to show your “cancel” action.

    $request->setDispatched(false)
            ->setControllerName("error")
            ->setActionName("jsonDecoding");
    

    The last way could be to just throw a exit after the echo “{error: “invalid json”}” not very nice but you will avoid the overload of having another dispatch iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Within a Zend app, is there a way to define a class which does
During sign-in I'm using following function to set cookies and session protected function validateUser($userid,
During an interview I was asked if there can be some object that will
PHP provides a mechanism to register a shutdown function: register_shutdown_function('shutdown_func'); The problem is that
During the project building, i received an error: Could not load JDBC driver class
During a discussion about security, a developer on my team asked if there was
During a typical day programming, I implement functions in a way that I would
During an upgrade from Zend Server CE 5.1 to Zend Server CE 5.5, PHP
Task: During the process of action of Zend Application to achieve next: - for
During a AuthnRequest, is there a case where the AudienceRestriction <saml:AudienceRestriction> <saml:Audience>http://serviceprovider.com/</saml:Audience> </saml:AudienceRestriction> would

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.