CakePHP 应用程序中的重定向循环

发布于 2024-09-16 04:13:34 字数 1724 浏览 2 评论 0原文

我在此处托管的 Web 应用程序使用 CakePHP v1.2: http://lol-land.in

应用程序直到昨天都工作正常,但突然开始陷入一些重定向循环。更奇怪的是,问题出在一个控制器上:posts。即使大多数功能都可以正常工作。但是 http://lol-land.in/posts 正在重定向到 lol-land.in/posts /view/133 又重定向到其自身。

实际上 /posts/view/ 形式的 117 个帖子中有 110 个被困在这个 302 重定向中。

谁能告诉我这可能是什么原因造成的?

[CakePHP 1.3 和 PHP5]

编辑:添加视图逻辑

function view($id = null) {
$this->log("View Logic Entry", LOG_DEBUG);
// These Log entires are missing 

$this->layout = 'postview';
if (!$id) {
    $this->Session->setFlash(__('Invalid Post.', true));
    $this->log("Redirect due to missing id", LOG_DEBUG);
    $this->redirect(array('action'=>'index'));
}
$log = $this->Session->read('Auth.User');
$logid = $log['id'];

$temp = $this->Post->read(null, $id);

$ratings = $temp['Rating'];

$this->set(compact('up', 'down', 'userrated', 'userrateid'));

$coms = $temp['Comment'];
$comuser = array();
for ($i=0; $i<count($coms); $i++) {
    $comuser[$i] = $coms[$i]['user_id'];
}
$comuser = $this->Post->User->find('list', array( 'fields'=>array('User.id', 'User.username'),
                      'conditions'=>array("User.id" => $comuser)
                      ));
$this->set(compact('comuser'));

$this->pageTitle = $temp['Post']['title'];
$this->set('post', $temp);
$alltypes = $this->Post->Type->find('list', array('fields'=> array('Type.id', 'Type.typename')));
$selectedtab = -1;
$this->set(compact('alltypes', 'selectedtab' ));


//Calling updateFBStats
// Removed because unnecessary.

}

I am using CakePHP v1.2 for my web application hosted here: http://lol-land.in

The application was working fine till Yesterday, but it suddenly started to get stuck in some redirection loops. What makes it weirder is the fact that the problem is with just one controller: posts. And even in that most of the functions are working. But http://lol-land.in/posts is redirecting to lol-land.in/posts/view/133 which is in turn redirecting to itself.

Actually 110 of the 117 posts of the form /posts/view/ are stuck in this 302 redirection.

Can anyone please tell me what could have caused this?

[CakePHP 1.3 and PHP5]

Edit: Adding View Logic

function view($id = null) {
$this->log("View Logic Entry", LOG_DEBUG);
// These Log entires are missing 

$this->layout = 'postview';
if (!$id) {
    $this->Session->setFlash(__('Invalid Post.', true));
    $this->log("Redirect due to missing id", LOG_DEBUG);
    $this->redirect(array('action'=>'index'));
}
$log = $this->Session->read('Auth.User');
$logid = $log['id'];

$temp = $this->Post->read(null, $id);

$ratings = $temp['Rating'];

$this->set(compact('up', 'down', 'userrated', 'userrateid'));

$coms = $temp['Comment'];
$comuser = array();
for ($i=0; $i<count($coms); $i++) {
    $comuser[$i] = $coms[$i]['user_id'];
}
$comuser = $this->Post->User->find('list', array( 'fields'=>array('User.id', 'User.username'),
                      'conditions'=>array("User.id" => $comuser)
                      ));
$this->set(compact('comuser'));

$this->pageTitle = $temp['Post']['title'];
$this->set('post', $temp);
$alltypes = $this->Post->Type->find('list', array('fields'=> array('Type.id', 'Type.typename')));
$selectedtab = -1;
$this->set(compact('alltypes', 'selectedtab' ));


//Calling updateFBStats
// Removed because unnecessary.

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤千羽 2024-09-23 04:13:34

您可能是 1) 对 Auth 组件使用循环引用,或者 2) 控制器中的函数将 do 重定向到方法中的某些内容。你能展示 posts_controller.php 函数 view() 的代码吗?

Chances are you are either 1) using circular references with the Auth component OR 2) the function in your controller is redirecting do to something within the method. Can you show the code of posts_controller.php function view() ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文