Issues

ZF-5895: isDispatched() not checked after action helper preDispatch() in action dispatch()

Issue Type: Bug Created: 2009-02-26T12:52:25.000+0000 Last Updated: 2009-03-10T07:58:49.000+0000 Status: Postponed Fix version(s): Reporter: Justin Hendrickson (toxygene) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments:

Description

Current, the dispatched flag is only checked once both the helpers preDispatch and the actions preDispatch have been called.

<pre class="highlight">
    // summarized
    public function dispatch($action)
    {
        // Notify helpers of action preDispatch state
        $this->_helper->notifyPreDispatch();

        $this->preDispatch();
        if ($this->getRequest()->isDispatched()) {
                $this->$action();
                $this->postDispatch();
        }
        $this->_helper->notifyPostDispatch();
    }

This means that the controllers preDispatch() method is always called, even when $this->$action() may not be called. At the very least, this seems to be inefficient. At worst, a careless (ie me) programmer might write an action helper that sets dispatch to false and ends up chasing his tail for an hour trying to figure out why his preDispatch() is still being called.

It seems to me that the dispatch method should look something like this:

<pre class="highlight">
    // summarized
    public function dispatch($action)
    {
        // Notify helpers of action preDispatch state
        $this->_helper->notifyPreDispatch();

        if ($this->getRequest()->isDispatched()) {
            $this->preDispatch();
            if ($this->getRequest()->isDispatched()) {
                    $this->$action();
                    $this->postDispatch();
            }
        }
        $this->_helper->notifyPostDispatch();
    }

Comments

Posted by Matthew Weier O'Phinney (matthew) on 2009-03-10T07:58:44.000+0000

While I can see some use cases for this, changing it at this time would introduce a fairly significant BC break. Marking it as postponed.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts