return $this->redirect 没有重定向到目标

return $this->redirect not redirecting to target

我有以下功能subscribe:

public function subscribe() {
    $plans = Configure::read('Stripe.american_plans');
    $plans['premium_american_monthly'] = __('Premium Monthly') . ' - 4.99';
    $plans['premium_american_annually'] = __('Premium Annually') . ' - 49.99';

    if ($this->request->is('post')) {
        $user = $this->Users->get($this->Auth->user('id'));

        if ($this->Users->save($user)) {
            $this->Flash->success(__('Your account has been subscribed'));
            debug($this->redirect(['controller' => 'Users', 'action' => 'edit']));
            die();
        } else {
            $this->Flash->error('User could not be subscribed.');
        }
    }

    $this->set(compact('plans'));
}

在将 $users 对象保存到实际函数中之前,我确实对其进行了操作,但这是我可以创建该函数并让页面仍然加载并且错误仍然发生的最简单方法。

围绕重定向的调试语句是为了检查它将用户重定向到哪里,结果显示:

object(Cake\Http\Response) {

'status' => (int) 302,
'contentType' => 'text/html',
'headers' => [
    'Content-Type' => [
        (int) 0 => 'text/html; charset=UTF-8'
    ],
    'Location' => [
        (int) 0 => 'https://localhost/users/subscribe'
    ]
],
'file' => null,
'fileRange' => [],
'cookies' => [
    'cookies go here'
    ]
],
'cacheDirectives' => [],
'body' => ''

}

如您所见,它没有重定向到我期望的位置。事实上,无论我在重定向语句中输入什么,它总是重定向到同一个函数,subscribe.

我不知道我做错了什么,因为这段代码看起来与其他功能相同,我可以正常使用该功能。有谁知道如何将此重定向到我想要重定向的位置?

感谢@ndm 的评论,让我找到了解决方案。这感觉像是一个肮脏的解决方案,因为我认为我没有解决实际问题,但它确实有效。在我重定向之前,我添加了以下内容:

$url = Router::url(['controller' => Users', 'action' => 'edit']);
$this->response = $this->response->withLocation($url);

问题的发生是因为我的 headers 某处已经设置了错误的位置。我不确定这是在哪里发生的,因为我们的其他重定向逻辑的 none 被击中了,而且我们没有在我们的代码中的任何地方实现 beforeRedirect

但是,正如我所说,这有效并且确实解决了问题。