CakePHP Page Occasionally a Losing Layout - Help?

I have a CakePHP website whose homepage is cached for 10 minutes at a time using Cake's default settings. However, I was warned that “every once in a while,” once a day or so, he was losing the layout by simply displaying the contents of the page without a title, style, etc.

Removing the cached version and restoring the page seems to fix the problem. But why could this happen in the first place? I can’t say I saw this happening myself (in any of my CakePHP projects), but does anyone else have any experience with this or any ideas on how to fix it? Really appreciate!

EDIT: looking at the file with the damaged home.php cache compared to the working cache file, I noticed this line:

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

It is like a breakthrough. I assume that sometimes a page is called using an Ajax request and then cached in this format until the cache expires. Does anyone know why this could happen (I don’t think we are trying to call the main page via Ajax anywhere, and we don’t even have an ajax layout!), And if anything we can do to stop it?

+6
source share
2 answers

Also, if you have any errors in your view, sometimes it doesn't load the layout. He will simply spit out the view until he encounters an error. Perhaps the error is not in displaying your layout, but in some strange case, when you cause an error with the help of an assistant.

0
source

Are you sure ajax requests do not interfere with your code / request?

We recently had a nightmare issue when the cake did not show the layout on the reverse / cross browser. See here CakePHP with no layout on the back and forward buttons

It can also help study the pie request loop ( http://book.cakephp.org/2.0/en/getting-started/a-typical-cakephp-request.html ) and narrow down when an error occurs in the request (and where), although I don’t know how you will reproduce it :)

I hope you find out!

+1
source

Source: https://habr.com/ru/post/893179/


All Articles