Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP Page Occasionally Losing Layout - Help?

I have a CakePHP site whose homepage is cached for 10 minutes at a time using Cake's default options. However I've been alerted that "every once in a while", once a day or so, it's losing the layout, just displaying the page content without the header, styling etc.

Removing the cached version and regenerating the page apparently fixes the problem. But why would/could this be happening in the first place? I can't say I've seen it happen myself (in any of my CakePHP projects) but does anyone else have any experience of this, or any ideas of ways to fix? Much appreciated!

EDIT: Looking at a broken cached home.php file compared to a working cache file, I've spotted this line:

$controller->layout = $this->layout = 'ajax'; //broken
$controller->layout = $this->layout = 'default'; //working

This seems like a bit of a breakthrough. I guess that sometimes the page is being called by an Ajax request, and then being cached in that format until the cache expires. Anyone know why this might be happening (I don't think we're trying to call the homepage via Ajax anywhere, and we don't even have an ajax layout!) and if there's anything we can do to stop it?

like image 978
thesunneversets Avatar asked Jul 20 '11 15:07

thesunneversets


1 Answers

Are you sure no ajax requests are interfering with your code/request?

We had a nightmare issue recently where cake was not rendering the layout on back/forward browser clicks. See here: CakePHP no layout on back and forward button

It may also help to look into the cake request cycle (http://book.cakephp.org/2.0/en/getting-started/a-typical-cakephp-request.html) and narrow down when in the request (and where) the error is occurring, although I dunno how you would reproduce it :)

Hope you figure it out!

like image 152
Jongosi Avatar answered Oct 15 '22 21:10

Jongosi