I have the below code in one of my controller files.$this->Flash->error("error message!");
return $this->redirect(['controller' => 'users', 'action' => 'home']);
.My problem is, flash message is not displaying on the redirected page. Can anyone help?
Asked
Active
Viewed 565 times
0

web_developer
- 71
- 1
- 9
-
Flash messages are stored in the session, make sure it's working (ie that you're receiving the session cookie, the cookie is sent after the redirect, the session is picked up, etc...) – ndm Feb 23 '20 at 23:11
-
Having cakephp 2 and it is not working too. – neobie Jun 09 '21 at 14:47
1 Answers
1
in controller:
$this->Flash->error("error message!");
return $this->redirect(['controller' => 'users', 'action' => 'home']);
in your home.ctp or layouts/default.ctp
<?= $this->Flash->render() ?>
** in your Element/Flash**
create error.ctp if . not exists

Salines
- 5,674
- 3
- 25
- 50
-
1
-
1set cakephp debug to true, clear browser cache, open developer tools and double check does flash message exist in your html code (maybe hidden by css) – Salines Feb 23 '20 at 22:34
-
-
-
1None of them are working. when I commented out the ```return $this->redirect(['controller' => 'users', 'action' => 'home']);``` line in controller, flash message displays on that page, but does not display after redirect. – web_developer Feb 23 '20 at 22:53
-