2010年1月26日星期二

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

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
-------



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

没有评论: