CakePHP redirect method not redirecting

一笑奈何 提交于 2019-12-24 01:08:25

问题


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.

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.

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.


回答1:


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

You can do redirection using JavaScript within ajax success method.

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.



来源:https://stackoverflow.com/questions/12384606/cakephp-redirect-method-not-redirecting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!