views:

458

answers:

3

I am having some issues with a site that was working correctly until i implemented full page caching in CakePHP.

I have followed the guidance in the Manual and have my $session->flash in a no-cache block as so:

<cake:nocache>
 <? 
 if($session->check('Message.flash')){
  $session->flash();
 } 
 ?>
</cake:nocache>

However, whenever a controller sets a flash message and redirects to a cached page the page loads down to the tag and then gives the error:

Notice (8): Trying to get property of non-object
[CORE/cake/libs/view/helpers/session.php, line 145]

Fatal error: Call to undefined method stdClass::renderLayout() in
/home/decipherd/domains/example.com/public_html/beta/cake/libs/view/helpers/session.php
on line 14

If i then go to a page created by another controller the correct (delayed) message is displayed and the page loads correctly.

I have now submitted this to the CakePHP trac as ticket 282

+1  A: 

Sounds like it might be an issue with the core, have you tried submitting a bug report?

Matt Huggins
it is now submitted here: http://code.cakephp.org/tickets/view/282
Tom
Looking into the core code of the SessionHelper, it appears that it's not an issue with the $session object not existing in the view, but an object with the key 'view' not being able to be retrieved from the ClassRegistry when you call $session->flash(). When you turn caching on, Cake probably has code that does not create a 'view' object, which then causes the issue you're seeing. You'll probably need to submit a bug report, or alternatively, manually display the contents of $session->read('Message.flash.message');
Matt Huggins
As i can't afford for to wait for the bug report to be fixed i am going to give manually displaying the contents ago and will report back, thanks
Tom
Matt, i can read the flash message manually but as you cannot write to the session from a view i cannot remove it afterwards, so the message keeps displaying on subsequent pages - any ideas?
Tom
The SessionHelper's del method still exists, so immediately after you read from it, just call $session->del('Message.flash');
Matt Huggins
aha, thankyou..
Tom
+1  A: 

Are you sure that there is something in the flash message? Try:

debug($session->read());

OR to output it to the debug.log

$this->log($session->read(), LOG_DEBUG); // this might not work in the view?
jimiyash
+1  A: 

Looking at the error message, it seems as is SessionHelper is not available for some reason.

I am not sure why exactly, this helper is usually loaded automatically when using AuthComponent or SessionComponent in your application.

Just a guess, but it might be worth putting $helpers = array('Session', ...); in your problem controller or AppController for good measure.

You can inspect everything available to your view with debug($this);

Ultimately, I would take Matt's advice and upgrade to the latest stable version anyway.

deizel
I have upgraded to the latest stable and added 'Session' to the helpers array. It appears as though the SessionHelper has loaded correctly, although the same error is occuring..
Tom