gotoSimple() 似乎在重定向之前重新加载到当前操作

发布于 2024-12-11 18:21:45 字数 1375 浏览 0 评论 0原文

不知何故,当我在以下设置中使用 gotoSimple 时,我的数据将被 secondAction()< 中的 $object->save() 保存两次/代码>。

public function firstAction(){
    // get data

    // process postdata, if any

    if( $form->isValid( $postdata ) ) {
        $this->_helper->getHelper( 'Redirector' )->gotoSimple( 'second' );
    }

}

public function secondAction(){

    // get data

    // process postdata, if any

    if( $form->isValid( $postdata ) ) {
        if( $object->save( $postdata ) ) {
            // set flashmessage
            $this->_helper->getHelper( 'Redirector' )->gotoSimple( 'index' );
        }
    }

}

经过几个小时的调试,我得出的结论是,secondAction() 中的 gotoSimple() 命令在重定向到之前会触发 secondAction() indexAction()。我已确保 indexAction() 不可能重定向回 secondAction()

更有趣的是:这只发生在 IE7 和 IE8 中。谁能向我指出这种奇怪行为可能来自何处以及如何解决这个问题?

更新 通过在 gotoSimple() 命令之前的 secondAction() 中使用以下代码行,我可以 100% 确定 secondAction(当我按下提交按钮时, ) 被调用两次:

if( isset( $_SESSION['xyz-zyx'] ) ) {
    $this->_helper->getHelper( 'flashMessenger' )->addMessage( 'I\'ve already been here!' );
    unset( $_SESSION['xyz-zyx'] );
}
$_SESSION['xyz-zyx'] = true;

有什么想法吗?

Somehow it seems that when I use gotoSimple in the following setup, my data will be saved twice by $object->save() in secondAction().

public function firstAction(){
    // get data

    // process postdata, if any

    if( $form->isValid( $postdata ) ) {
        $this->_helper->getHelper( 'Redirector' )->gotoSimple( 'second' );
    }

}

public function secondAction(){

    // get data

    // process postdata, if any

    if( $form->isValid( $postdata ) ) {
        if( $object->save( $postdata ) ) {
            // set flashmessage
            $this->_helper->getHelper( 'Redirector' )->gotoSimple( 'index' );
        }
    }

}

After hours of debugging I have come to the conclusion that somehow the gotoSimple() command in secondAction() triggers secondAction() before it redirects to indexAction(). I have made sure that it is in no way possible for indexAction() to redirect back to secondAction().

Even more interesting: this only occurs in IE7 and in IE8. Can anyone point me in any possible direction to where this strange behavior may come from and how I can solve this?

UPDATE
By using the following lines of code in secondAction() right before the gotoSimple() command, I can be 100% sure of the fact that somehow the secondAction() is called twice when I press my submit button:

if( isset( $_SESSION['xyz-zyx'] ) ) {
    $this->_helper->getHelper( 'flashMessenger' )->addMessage( 'I\'ve already been here!' );
    unset( $_SESSION['xyz-zyx'] );
}
$_SESSION['xyz-zyx'] = true;

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲世九天 2024-12-18 18:21:45

检查您的服务器日志或监视您的网络,您将看到浏览器在实际重定向之前发送相同的请求两次。

我在浏览器中看到了许多行为,它们发送请求两次。有多种原因,但附加组件也会引发第二个请求,从而扰乱您的应用程序。在一种情况下,问题很简单,例如缺少 favicon.ico 或图像文件的链接已损坏。这一切都很好,并且在您开始处理会话状态或表单提交之前不会打扰您。

一旦您知道触发第二个请求的原因,您不仅应该修复该问题,还应该添加其他措施以防止来自任何浏览器的第二个请求。

Check your server log or monitor your network and you will see that the browser is sending the same request twice--before the actual redirect.

I have seen many behaviors in browsers where they send a request twice. There are several reasons but also add-ons which fire a second request messing with your application. In one case it was something simple like a missing favicon.ico or a broken link to a image file. This all is fine and doesn't bother you until you begin working with session state or form submissions.

Once you know what is triggering the second request you should not only fix that but also add additional measures to prevent a second request from any browser.

可爱咩 2024-12-18 18:21:45

看来问题是由使用 Zend_DataGrid (BvBGrid) 引起的。重写了整个动作并解决了问题:)

It seems that the problem was caused by using Zend_DataGrid (BvBGrid). Rewrote the entire action and fixed the problem :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文