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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:02:34+00:00 2026-06-03T18:02:34+00:00

Zend Framework 1.11.11 I am writing a Zend Framework Controller Plugin that does stuff

  • 0

Zend Framework 1.11.11

I am writing a Zend Framework Controller Plugin that does stuff in the routeShutdown hook.

I’d like to be able to avoid running my processes if there are routing errors.

i.e. I do not want to run the processes if we are just gonna get a 404 error.

class MyPlugin extends Zend_Controller_Plugin_Abstract
    {


    public function routeShutdown( Zend_Controller_Request_Abstract $zfRequestObj )
        {

        if ( $this->isRoutingError() )
            {
            //there was a routing error do not do any intensive page start up stuff
            return;
            }

        return $this->doRouteShutdownProcesses( $zfRequestObj );                
        }

    protected function isRoutingError()
            {
            //?? So how do we get this?
            }
    ...

    }

So, how can we determine if there was a routing error at this point?

Things I have tried.

  • Check the module, controller, action name in the requestObj

    • Does not work cos that is not set to Error Action yet
  • Check for exceptions in response object

    • Does not work cos $this->getResponse()->isException() seems to return FALSE, even when there was a routing error.

Any help appreciated.

  • 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-03T18:02:42+00:00Added an answer on June 3, 2026 at 6:02 pm

    I have worked it out myself.

    I was being stupid. At routeShutdown we do not know whether its going to be a 404 page type error until we try to dispatch it.

    So all we can do is

    • test for general exceptions in the response
    • ask the dispatcher if the route is likely to be Dispatchable.

    So the plugin cannot really determine if there is a ‘routing error’ – so it has to ask “isRouteShutdownToBeSkipped()” :

    <?php
    
    class MyPlugin extends Zend_Controller_Plugin_Abstract
        {
    
    
        public function routeShutdown( Zend_Controller_Request_Abstract $zfRequestObj )
            {
    
            if ( $this->isRouteShutdownToBeSkipped( $zfRequestObj ) )
                {
                //do not do any intensive page start up stuff
                return;
                }
    
            return $this->doRouteShutdownProcesses( $zfRequestObj );                
            }
    
        //...
    

    Then the isRouteShutdownToBeSkipped() method tests for

    • general exceptions, or for
    • undispatchable controllers
    • action methods that do not exist. (I avoid using magic in my project, so I know that if the method aint declared, then it aint gonna work.)

    So:

    <?php
    
    class MyPlugin extends Zend_Controller_Plugin_Abstract
        {
    
        //...
    
        protected function isRouteShutdownToBeSkipped( Zend_Controller_Request_Abstract $zfRequestObj )
            {   
    
            if ( $this->getResponse()->isException() )
                {
                //Skip cos there was an exception already.
                return TRUE;
                }
    
            if (!( $this->isDispatchable( $zfRequestObj ) )) 
                {
                //Skip cos route is not dispatchable (i.e no valid controller found).
                return TRUE;
                }
    
    
            if (!( $this->actionMethodExists( $zfRequestObj ) ))
                {
                //There is no action method on the controller class that 
                //resembles the requested action.
                return TRUE;
                }
    
            //else else give it a go
            return FALSE;
            }
        //...
    

    My isDispatchable() method simply delegates to the dispatcher:

    <?php
    
    class MyPlugin extends Zend_Controller_Plugin_Abstract
        {
    
        //...
    
        protected function isDispatchable( Zend_Controller_Request_Abstract $zfRequestObj )
            {
            return Zend_Controller_Front::getInstance()
                ->getDispatcher()
                ->isDispatchable( $zfRequestObj );      
            }
        ...
    

    My actionMethodExists() method is a little bit more complex. The dispatcher’s interface is a bit misleading (getControllerClass() does not actually return a classname), so we have to jump through some hoops to get the actual controller class name, then load the class in time for the call to PHP’s builtin method_exists() function:

    <?php    
    class MyPlugin extends Zend_Controller_Plugin_Abstract
        {    
        //...
    
        /**
        * @desc 
        * @returns boolean - TRUE if action method exists
        */
        protected function actionMethodExists( Zend_Controller_Request_Abstract $zfRequestObj )
            {
    
            //getControllerClass() does not return the module prefix
            $controllerClassSuffix = Zend_Controller_Front::getInstance()
                ->getDispatcher()
                ->getControllerClass( $zfRequestObj );
    
    
            $controllerClassName = Zend_Controller_Front::getInstance()
                ->getDispatcher()
                ->formatClassName( $zfRequestObj->getModuleName() , $controllerClassSuffix );
    
    
            //load the class before we call method_exists()
            Zend_Controller_Front::getInstance()
                ->getDispatcher()
                ->loadClass( $controllerClassSuffix );
    
            $actionMethod = Zend_Controller_Front::getInstance()
                ->getDispatcher()
                ->getActionMethod( $zfRequestObj );
    
            return ( method_exists( $controllerClassName, $actionMethod ) );
            }
    
        //...
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a plugin for my Zend Framework app and want to do a
In Zend Framework, Controller plugins are common for instantiating and configuring resources that every
Does anyone has experience with ZEND's framework for writing a RESTful API for an
I am used to writing unit tests in Zend Framework 1.9 using PHPUnit_Framework_TestCase for
Zend Framework FrontController implements Singleton and plus it has some kind a plugin paradigm
The zend framework provides a php wrapper for the amazon S3 api that simplifies
In the Zend Framework Quickstart , there has been a change from models that
I'm new to Zend Framework. I would like to know how to implement zend
I'm writing a controller helper that sets the proper response headers for my REST
I'm writing a webapp using Zend framework and a homebrew widget system. Every widget

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.