我想在登录后重定向上一页。我的第一个问题是最好的解决方案是什么?
我尝试以下解决方案。 在 get 请求中发送上一页 url 并重定向到 get 请求中的 url。
这是我上一个页面的操作。
public function executeVotes(sfWebRequest $request)
{
$chaletId = (int) $request->getParameter('id');
$this->rates = (int) $request->getParameter('rates', 0);
if (
($this->getUser()->isAuthenticated() === FALSE )
|| ($this->getUser()->hasCredential('member_permission') === FALSE)
) {
$this->redirect('member_signin', array(
'redirect' => $this->getController()->genUrl('chalet_votes/' . $chaletId . '/?rates=' . $this->rates, true)
));
}
}
这是我的登录操作
public function executeSignin(sfWebRequest $request)
{
$this->redirectUrl = $this->getRequest()->getParameter('redirect');
echo $this->redirectUrl; die;
}
这是这些操作的路由器。
member_signin:
url: /member/login/*
param: { module: member, action: signin}
votes:
url: /chalet/votes/:id
param: { module: test, action: votes }
这是重定向到登录页面后的网址。
http://test.dev/member/login/redirect/http%3A%2F%2Fchalet.dev%2Fchalet_votes%2F1%2Frates%2F9
我的服务器显示 404 页面错误。有什么问题吗?我该怎么做?
最佳答案
而不是将未经身份验证的用户重定向到member_signin
。尝试转发它们:
$this->forward('member_signin');
由于您没有重定向,因此当您发布登录表单时,您将在 $request->getReferer()
方法中获得引用网址。
那么您需要在登录操作中执行以下操作:
public function executeSignin(sfWebRequest $request)
{
$user = $this->getUser();
// If the user has been authenticated, helps prevent redirect loop as well.
if ($user->isAuthenticated()) {
$this->redirect('@defaultpage');
}
// Do authentication
//...
// If authenticated
$this->redirect($request->getReferer());
}
关于php - Symfony 1.4 - 在 get 请求中传递 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16561254/