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

  • Home
  • SEARCH
  • 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 9229067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:28:52+00:00 2026-06-18T05:28:52+00:00

I have an issue which was reported here ( http://framework.zend.com/issues/browse/ZF2-379?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab#issue-tabs ). There is a

  • 0

I have an issue which was reported here (http://framework.zend.com/issues/browse/ZF2-379?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab#issue-tabs). There is a solution, but I have no idea where to implement that. Anyone can help?

Regards,

  • 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-18T05:28:54+00:00Added an answer on June 18, 2026 at 5:28 am

    Here’s code for a JsonExceptionStrategy – put it somewhere, like in a module.

    namespace YourNamespace;
    
    use Zend\EventManager\EventManagerInterface;
    use Zend\Mvc\Application;
    use Zend\Mvc\View\Http\ExceptionStrategy;
    use Zend\Mvc\MvcEvent;
    use Zend\View\Model\JsonModel;
    
    /**
     *
     * @since   1.0
     * @author  Tim Roediger <superdweebie@gmail.com>
     */
    class JsonExceptionStrategy extends ExceptionStrategy
    {
    
        /**
         * Attach the aggregate to the specified event manager
         *
         * @param  EventManagerInterface $events
         * @return void
         */
        public function attach(EventManagerInterface $events)
        {
            $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'prepareExceptionViewModel'), 100);
        }
    
        /**
         * Create an exception json view model, and set the HTTP status code
         *
         * @todo   dispatch.error does not halt dispatch unless a response is
         *         returned. As such, we likely need to trigger rendering as a low
         *         priority dispatch.error event (or goto a render event) to ensure
         *         rendering occurs, and that munging of view models occurs when
         *         expected.
         * @param  MvcEvent $e
         * @return void
         */
        public function prepareExceptionViewModel(MvcEvent $e)
        {
            // Do nothing if no error in the event
            $error = $e->getError();
            if (empty($error)) {
                return;
            }
    
            // Do nothing if the result is a response object
            $result = $e->getResult();
            if ($result instanceof Response) {
                return;
            }
    
            switch ($error) {
                case Application::ERROR_CONTROLLER_NOT_FOUND:
                case Application::ERROR_CONTROLLER_INVALID:
                case Application::ERROR_ROUTER_NO_MATCH:
                    // Specifically not handling these
                    return;
    
                case Application::ERROR_EXCEPTION:
                default:
                    $exception = $e->getParam('exception');
                    $modelData = array(
                        'message' => $exception->getMessage(),
                        'type' => get_class($exception)
                    );
    
                    if ($this->displayExceptions()){
                        $modelData['exception'] = $exception;
                    }
                    $e->setResult(new JsonModel($modelData));
                    $e->setError(false);
    
                    $response = $e->getResponse();
                    if (!$response) {
                        $response = new HttpResponse();
                        $e->setResponse($response);
                    }
                    $response->setStatusCode(500);
                    break;
            }
        }
    }
    

    Then add the following in your Module.php:

    /**
     *
     * @param \Zend\EventManager\Event $event
     */
    public function onBootstrap(MvcEvent $event)
    {
    
        $application = $event->getTarget();
        $serviceManager = $application->getServiceManager();
        $config = $serviceManager->get('Config');
    
        // Config json enabled exceptionStrategy
        $exceptionStrategy = new JsonExceptionStrategy();
    
        $displayExceptions = false;
    
        if (isset($config['view_manager']['display_exceptions'])) {
            $displayExceptions = $config['view_manager']['display_exceptions'];
        }
    
        $exceptionStrategy->setDisplayExceptions($displayExceptions);
        $exceptionStrategy->attach($application->getEventManager());
    }
    

    You’re good to go!

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

Sidebar

Related Questions

I have an issue which seems to have been reported here: Need razor view
I have an issue which I could not find answer for across the web.
I have some urgent issue which I could not find answer for across the
I have yet another issue which the answer is eluding me. I wish to
i have a small issue which my text field insist to inhert the CSS
I have an issue with log4net which has been bugging me for a while
I have been working on a json decode issue (which I have already had
I'm pretty new in iphone programming and have stumbled upon this issue which I
I am fairly new to C++, but i have ran into an issue which
I have an issue working with Microsoft.Build.BuildEngine which supposed to get fixed modifing my

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.