开发者

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 开发者_JAVA技巧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?


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!


Also, if you have any errors in your view, sometimes it won't load the layout. It will just spit out the view until the point where it experienced the error. Perhaps the error is not in displaying your layout, but some odd circumstance where you are generating an error with a Helper.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜