2010年1月27日星期三

Re: [fw-mvc] Stop Dispatching Process not working

Hello again,

ok, this works. but this was not my biggest problem.

If i change my request to a empty controller, this needs 32 milliseconds (just for dispatching - because of some plugins and my view controller) and the hole loading of the page needs 92 milliseconds. If i change the ZF Front.php to stop the dispatching (i don't need the dispatching because the output is cached) my hole script needs aprox. 70 - 75 milliseconds. This is my problem and i think is necessary to build a function to stop dispatching in the official ZF.

I cannot use the Zend_Page cache, because i have some Controller Plugins/helper for tracking and so on.

Where can i submit a feature request ?

Thanks

Marcel

Am 26.01.2010 um 18:53 schrieb Hector Virgen:

The current code is working as expected. From what I understand, if the request is marked as "not dispatched", then the dispatch loop is started over again, which is why it uses "continue".

So you were correct, you should be setting the dispatched flag to false, but in order to prevent an infinite loop you need to to test from within your plugin if it has already run or not. This can be done with an $_enabled property:

protected $_enabled = true;

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
    if (true === $this->_enabled) {
        $request->setDispatched(false);
        // Prevent this plugin from running on the next dispatch loop
        $this->_enabled = false;
    }
}

If you want to skip the current action but continue with the rest of the dispatch loop, alter the request (perhaps by setting it to a dummy controller/action) and set the dispatched flag to false.

Other than that, I don't think there's a way to exit the dispatch loop unless you use exit.

--
Hector


On Tue, Jan 26, 2010 at 4:29 AM, Marcel Alburg <m.alburg@weeaar.com> wrote:
Hello,

this is not working.

If i Register my Cache Plugin to my Frontcontroller an set the $request->setDispatched(true) in the PRE DISPATCH() (i'll stop the hole dispatch process) - the script run into endless.

a Snipped from the ZF doku.

preDispatch() is called before an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via Zend_Controller_Request_Abstract::setDispatched(false)), the current action may be skipped and/or replaced.                 


my Plugin.

  class Default_Plugin_Cache extends Zend_Controller_Plugin_Abstract
  {
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
      $this->_sCacheString = md5( $request->getRequestUri() . ' ' . $request->getControllerName() . ' ' . $request->getActionName() . ' ' . __DEFAULT_MODULE__); 

      if ( ($return = Default_Cache::checkCache($this->_sCacheString)) )
      {
...
        $request->setDispatched(false);
      }
...
    }


and the Front.php from the ZF Beta.

            do {
                $this->_request->setDispatched(true);

                /**
                 * Notify plugins of dispatch startup
                 */
                $this->_plugins->preDispatch($this->_request);

                /**
                 * Skip requested action if preDispatch() has reset it
                 */
                if (!$this->_request->isDispatched()) {
                    continue;
                }

                /**
                 * Dispatch request
                 */
                try {
                    $dispatcher->dispatch($this->_request, $this->_response);
                } catch (Exception $e) {
                    if ($this->throwExceptions()) {
                        throw $e;
                    }
                    $this->_response->setException($e);
                }

                /**
                 * Notify plugins of dispatch completion
                 */
                $this->_plugins->postDispatch($this->_request);
            } while (!$this->_request->isDispatched());


because of that, it is NOT POSSIBLE (runs to endless) to stop Dispatching from the preDispatch but i need this.

in my opinion, the "continue" must be change to "break";

Thanks
Marcel


Am 26.01.2010 um 01:54 schrieb Hector Virgen:

I think you want to use $request->setDispatched(true). That should inform the dispatcher that the request has already been fulfilled and continue on to postDispatch().

--
Hector


On Mon, Jan 25, 2010 at 5:27 AM, Marcel Alburg <m.alburg@weeaar.com> wrote:
Hello,

is it possible to Implement a Hook/Callback to stop dispatching in the FrontController in a official version of ZF ?

Thanks
Marcel


Am 22.01.2010 um 17:17 schrieb Marcel Alburg:

> Hi,
>
>
> i played with ZF 1.10beta and wrote a Zend_Controller_Plugin
>
>   class Default_Plugin_Cache extends Zend_Controller_Plugin_Abstract
>   {
>     public function preDispatch(Zend_Controller_Request_Abstract $request)
>     {
>        ...
>       $request->setDispatched(false);
>        ...
>     }
>   }
>
> this should stopping the dispatching process but it not works. The snipped (Zend_Controller_Request_Abstract::setDispatched(false);) from the ZF Doku works not too.
>
> if i look in the Zend/Controller/Front.php line 941 i found this
>
>   $this->_plugins->preDispatch($this->_request);
>
>                 /**
>                  * Skip requested action if preDispatch() has reset it
>                  */
>                 if (!$this->_request->isDispatched()) {
>                    continue;
>                 }
>
> i wonder because a continue begins the while loop again. if i change continue to break it works correctly for me.
>
>
> Marcel



--  Weeaar Web- und Softwareentwicklung  http://www.weeaar.com/  Tel: +49 (0)30 2089 6809 Mail: m.alburg@weeaar.com  SteuerID: 049 / 200 / 00385 Inhaber: Marcel Alburg
-------

<banner_728x90.png>
 

www.beatboat.de - Dein Musikpreisvergleich
Nominiert für den Onlinestar 2009



--  Weeaar Web- und Softwareentwicklung  http://www.weeaar.com/  Tel: +49 (0)30 2089 6809 Mail: m.alburg@weeaar.com  SteuerID: 049 / 200 / 00385 Inhaber: Marcel Alburg
-------



www.beatboat.de - Dein Musikpreisvergleich
Nominiert für den Onlinestar 2009

没有评论: