dtpwra8456 2013-06-29 13:42
浏览 41
已采纳

Yii防止在刷新时从上传的文件中重新插入数据到数据库

I have an upload form, where I upload csv files and then insert all rows to the database. If I hit refresh, all content is inserted again and again into the database. What is the best prectice to prevent this?

Thanks a lot! BR

  • 写回答

2条回答 默认 最新

  • dongtan9066 2013-06-29 13:46
    关注

    The best way to prevent this behavior is to use a redirect to show the landing page. When a redirect is made the browser history records another url after the post action. in Yii you can achieve this by doing the following from the controller.

     $this->redirect("../path/to/action");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?