Reputation: 3137
I have a not-particularly complex CakePHP (1.3) setup. I've discovered a very puzzling behaviour apparently related to the view cache.
I'm caching two view files that grab a dynamic navigation using requestAction. If I delete one or both of these cache files from the filesystem, the browser hangs for a little while and then spits out an error page:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
Apache itself doesn't log any errors which is odd because if it had somehow got stuck in an infinite loop like Firefox thinks it does, surely it would show up in the log? If I put the cache files back, Cake displays everything as normal.
What is going on? Has anybody encountered anything like this before?
The request action calls look like this:
<?php
$topnav = $this->requestAction('/pages/getDynamicTopMenu');
foreach($topnav as $item):
if($item['Page']['title'] == 'Home') {
echo '<li class="'.$item['Page']['slug'].'">'.$this->Html->link($item['Page']['title'].'','/').'</li>';
} else {
echo '<li class="'.$item['Page']['slug'].'">'.$this->Html->link($item['Page']['title'].'','/pages/view/'.$item['Page']['slug'].'').'</li>';
}
endforeach;
?>
And the corresponding functions look like this:
function getDynamicTopMenu(){
return $this->Page->find('all', array(
'conditions' => array('Page.published =' => '1','Page.top_menu' => '1'),
'fields' => array('Page.title','Page.slug','Page.top_menu'),
'order' => array('Page.id')
));
}
Upvotes: 2
Views: 1834
Reputation: 359
I has this issue; in my case the reason was a malformed redirect path. Below, $defaultController was the name of my controller plus /something, so the redirect failed and had the error mentioned ealier. Cleaned $defaultController variable to no more than a valid controller and all good.
$this->redirect($this->Auth->redirect('/' . "$defaultController" . '/', array('action' => 'index')));
Upvotes: 1
Reputation: 3137
It turns out that this one was caused by using the Auth component but not adding the getDynamicTopMenu()
action to the allow array in app_controller.php.
Once getDynamicTopMenu was added to $this->Auth->allow()
, the problem melted away :-)
Upvotes: 1
Reputation: 33163
The page is redirecting the browser back to the same page over and over again, or it's redirecting to another page that redirects back to the original and so on. It's not an error that would show up in Apache's error logs--Apache just carries out the requests, it doesn't know that the site isn't supposed to do it.
Check for any redirects you may have and also make sure you're not using requestAction to request a page that contains itself (which would make it request itself again and so on). The cached page probably just makes the site not carry out the requestActions which circumvents the bug.
Upvotes: 0