php - Symfony 1.4 - 在 get 请求中传递 URL

标签 php symfony1 symfony-1.4

我想在登录后重定向上一页。我的第一个问题是最好的解决方案是什么?

我尝试以下解决方案。 在 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/

相关文章:

php - 使用 MySQL 从树中选择记录

php - 错误连接到Cloud 9中的DB

php - 如何添加自定义 "under maintenance"页面?

symfony1 - 从 Symfony 1.4 升级到 Symfony 2.0 所需的努力

php - Symfony - 是否可以禁用每个模块(或每个模板)的输出转义?

symfony1 - 在 Symfony 中,如何在类中使用 url_for 助手?

php - 为什么下划线在 PSR-0 中转换为目录分隔符?

关于 SSL 的 PHP cURL 错误

php - 永久删除 symfony 插件

symfony1 - 插入或 Doctrine ;对于 Symfony 1.4 来说哪个 ORM 更好