CakePhp刷新页面

时间:2012-06-10 11:23:09

标签: cakephp-2.0

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

我知道我可以渲染新页面或重定向到另一个页面,但我喜欢用setFlash显示一条消息,就是这样。有人可以帮帮我吗?

提前致谢

亚伦

2 个答案:

答案 0 :(得分:15)

更新:检查下面的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

重定向。

答案 1 :(得分: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');

}

希望这有帮助!

相关问题