Powered by Invision Power Board



  Reply to this topicStart new topicStart Poll

> setFlash not clearing with custom helper
bryanlee
Posted: Oct 14 2010, 01:35 AM
Quote Post


Newbie
*

Group: Members
Posts: 2
Member No.: 2342
Joined: 14-October 10



Hi, all. I'm a relative newbie to CakePHP and I'm running into this bizarre problem. Basically, I was setting a flash message using $this->Session->setFlash('Foo'); and it would appear ok on the page, but sometimes it would disappear after subsequent navigation, sometimes not.

I think I've traced it down to whether or not I include a custom helper or not in my controller - which seems really weird.

Here's my controller:
<?php
class GtestController extends AppController
{
var $name = 'gtest';

var $helpers = array('Html', 'Form', 'DateRange');

var $uses = array('User');

function flash_me()
{ // just testing
$this->Session->setFlash('Some flashy thing.');
$this->redirect(array('controller' => 'gtest', 'action' => 'foo'));
}

function foo()
{ testing
}
}
?>

DateRange is a custom helper. If I go to /app/gtest/flash_me and the /app/gtest/foo and keep refreshing, the flash message does not go away.

But if I simply remove the DateRange from the list of helpers:
var $helpers = array('Html', 'Form');
and then do the same thing, then it works as expected - the flash message appears once, then if I refresh on /foo it disappears.

Here's my DateRangeHelper - I commented out all the functions in it:
<?
/* /app/views/helpers/daterange.php */
class DateRangeHelper extends AppHelper {

}
?>


Has anyone seen anything like this before? Seems really bizarre to me.

I'm on CakePHP 1.3.0.

I tried it on IE7, Firefox, Chrome on Windows, Firefox on Linux - same behavior everywhere. (And yes I'm half-positive it will end up being something really silly, like oh I forgot a semicolon somewhere).

Thanks for any pointers you might have!

PMEmail Poster
Top
bryanlee
Posted: Oct 14 2010, 05:14 AM
Quote Post


Newbie
*

Group: Members
Posts: 2
Member No.: 2342
Joined: 14-October 10



Ok, I think I figured it out. After logging out _SESSION variables and things like that, it was looking almost like there were two separate $_SESSION variables - the one used by the view is where it deleted the flash message, but the controller one seemed to be separate.

And then I randomly tried adding 'Session' to the list of Helpers in the controller. Sure enough, that fixed it!

Then I read this in the 1.3 CakePHP book (and it's different from the 1.2 docs):
"The Session Helper is no longer automatically added to your view — so it is necessary to add it to the $helpers array in the controller."

Hope this helps someone else out there too!
PMEmail Poster
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:

Topic Options Reply to this topicStart new topicStart Poll

 

Disclaimer:
This forum is in no way affiliated with the Cake Software Foundation
The CakePHP name and icon is a trademark of the Cake Software Foundation


Lo-Fi Version