Yii语言控制使用行为如何防止表单重新提交对话框


Yii language control using behaviours how to prevent form resubmition dialog

我使用了本教程http://www.yiiframework.com/wiki/208/how-to-use-an-application-behavior-to-maintain-runtime-configuration/改变语言。但我遇到了一个问题,$_Post['lang']变量没有被重置,每次我尝试刷新页面时,它都会给我表单重新提交对话框,这是我不想有的。但我不知道在哪里以及如何使用重定向,因为它在behaviors类中不起作用。如何阻止此表单重新提交?

编辑:我发现了一个丑陋的解决方案,把这个代码放在我有的每个视图文件中

<?php
$this->renderPartial('//lang/_refresh', array())
?>

但它需要多次重复相同的代码,我相信有更好的解决方案(可能在正确的位置放置刷新功能)

找到了一个解决方案,你只需要在components/Controller中添加一个beforeAction,因为所有添加的控制器都扩展了它。问题是我不知道。这是一个有效的函数,这样我就不必重写代码了。

protected function beforeAction()
    {
        if (isset($_POST['lang'])) {
            $this->refresh();
        }
        return true;
    }