CakePHP的重定向方法不是重定向 [英] CakePHP redirect method not redirecting

查看:290
本文介绍了CakePHP的重定向方法不是重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重定向到使用CakePHP重定向的方法,但由于某些原因,重定向不工作新的一页。在code我使用重定向是

I am trying to redirect to a new page using CakePHP redirect method but for some reason the redirect is not working. The code I am using to redirect is

public function update_sticky_postition_in_db()
{   
     $this->autoRender = false;

     ... // Save info to database

     $this->redirect(array('action' => 'tool'));
}

在哪里的工具是我特林重定向到视图的名称。要尝试并加快发现我已经检查了一些东西,想我已经找到了问题的原因的问题的过程。基本上,我想重定向到当前处于活动状态,我认为就是为什么它不重定向的原因之一的观点。我已阅读,它可能有一些做的页面的缓存,但我不知道如何解决这个问题。

Where tool is the name of the view I am tring to redirect to. To try and speed the process of finding the problem I have checked few things and think I have found the cause of the problem. Basically I am trying to redirect to the view that is currently active which I think is part of the reason why it is not redirecting. I have read that it might have something to do with caching of the page but I am not sure how to solve that issue.

还利用萤火虫的时候,我可以看到重定向发送GET请求,但没有什么之后发生的事情。我必须做一些事情的GET请求或应蛋糕搞定我。此外,我已经检查了GET的URL,这是正确的。

Also when using firebug I can see the redirect is sending a GET request but after that nothing is happening. Do I have to do something with the GET request or should Cake handle that for me. Also I have checked the URL of the GET and it is correct.

坐落使用正确的名称在控制器内,我可以查看原始工具页面。

It is located within the controller with the correct name as I can view the original tool page.

另外,update_sticky_postition_in_db()方法没有一个视图(所以为什么自动渲染设置为false),其预期目的是从一个Ajax调用更新一行在数据库中。

Also the update_sticky_postition_in_db() method does not have a view (hence why the auto render is set to false), its intended purpose is to update a row in the database from an ajax call.

推荐答案

从您的文章似乎你射击的 update_sticky_postition_in_db()使用Ajax调用,从而使重定向将无法正常工作。

From your post it seems you're firing the update_sticky_postition_in_db() using ajax call, so that the redirection will not work.

您可以使用JavaScript中的AJAX做重定向成功方法。

You can do redirection using JavaScript within ajax success method.

为了做到这一点,你可以发送一些 json_en code()消息从你以上的方法和检查中阿贾克斯的状态成功方法,你可以用做一个重定向 window.location的

In order to do that, you may send some json_encode() message from you above method and checking that status within ajax success method you can do a redirect using window.location.

这篇关于CakePHP的重定向方法不是重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆