【问题标题】:CakePhp Refreshing pageCakePhp 刷新页面
【发布时间】:2012-06-10 11:23:09
【问题描述】:

我在 Cakephp 中有以下问题: 我制作了一个 CMS 来使用 CakePhp 编辑网站的内容。现在,当我更改表单中的内容并单击“保存”时,他再次显示表单更改之前的数据。 在数据库中,一切都保存得很好,如果我刷新页面,他也会显示正确的数据。

我知道我可以呈现一个新页面或重定向到另一个页面,但我喜欢只使用 setFlash 显示一条消息,仅此而已。有人可以帮帮我吗?

提前致谢

亚伦

【问题讨论】:

    标签: cakephp-2.0


    【解决方案1】:

    更新:查看下面的 Justin T. 解决方案。

    您可以重定向到同一页面:

    设置您的 Flash 消息:

    $this->setFlash('blablablabla');
    

    return $this->redirect($this->here); //cake 1.3
    

    return $this->redirect($this->request->here); // cake 2.x
    

    return $this->redirect(['controller' => 'MyController', 'action' => 'methodOfController']); // cake3.X
    

    重定向。

    【讨论】:

    • 不错!是的,这是我忘记的请求参数。谢谢
    • 使用Router :: url方法在redirect方法中写入url或者手动写入url添加子目录,Cakephp的配置中也有一些选项来管理子目录的情况
    • 也可以按照这里的建议重定向到 $this->referer() stackoverflow.com/a/16342239/421063
    【解决方案2】:

    使用new method flash(),您可以设置消息以相同的方法重定向。

    这是我所知道的最优雅的方式,它是这样的:

    <?php
    public function post() {
       // process content here...
    
    
       // redirects the user immediately with a nice message
       $this->flash('Your post has been updated, thanks', 'index');
    
    }
    

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 2016-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 2011-12-22
      • 2010-10-21
      • 2018-12-04
      相关资源
      最近更新 更多