如何在登录后返回CakePHP中的referer页面
回到referer页面时遇到问题:
first url: http://site.com/venue/apartments/1564/venue-name referer url: null 在这个页面我可以编辑里面的东西,所以我有一个登录按钮进入登录页面,成功登录后,我想回到第一个网址. second url: http://site.com/users/login referer url: http://site.com/venue/apartments/1564/venue-name 当我尝试登录时,由于CakePHP操作规则,我必须刷新登录页面以检查凭据,问题从这里开始: third url: http://site.com/users/login referer url: http://site.com/users/login 通过刷新页面,并检查用户控制器的登录操作中的凭据我得到的是我之前的相同页面,现在我不能回到第一个URL. 我通过在AppController中设置会话变量来尝试一些解决方案,该变量检查我是否在登录操作页面中并执行此操作: AppController.php public function beforeFilter () { $this->setRedirect(); } public function setRedirect () { if ($this->request->params['controller'] != 'users' && $this->request->params['action'] != 'login') { $this->Session->write('redir',array('controller'=>$this->request->params['controller'],'action'=>$this->request->params['action'],implode($this->request->params['pass'],'/'))); } } 通过调试会话var($this-> Session-> write(‘redir’));在我进行登录操作之前,一切似乎都很完美: UsersController.php public function login () { if ($this->request->is ('post')){ if ($this->Auth->login()) { $redir = $this->Session->read('redir'); if (!empty($redir)) { $this->redirect ($redir); } else { $this->redirect ($this->Auth->redirect()); } } } } 这样做会破坏应用程序,如果我调试($redir);我得到: array( 'controller' => 'js','action' => 'jquery',(int) 0 => 'plugin/jquery.validata.1.7.min' // just a jquery plugin loaded in default.ctp ) 代替 array( 'controller' => 'venue','action' => 'apartments',(int) 0 => '1564/venue-name' ) 如果我调试($redir);在整个网站的任何其他视图中,一切正常,我得到了正确的数据. 我想在$this-> Auth-> login()动作的某种会话保护例程中,但对我来说这完全是胡说八道. 如何才能将登录到最后一页的用户重定向到非登录视图页面?
你试过这个:$this-> redirect(Controller :: referer());?
我必须重读你的整个问题,但这也应该有效:$this-> redirect($this-> referer()); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |