dongmei2956 2017-08-14 06:32
浏览 154
已采纳

获取yii2中重定向请求的URL?

Sorry for my English, but what I'm trying to say is explained below.

I have a controller say ControllerCard which has an action like this.

function actionScanCard()
{
    ...
    $this->redirect('/transaction/redeem');
    ...
}

In other controllers, ControllerTransaction, I am trying to get that it comes/redirected from /card/scan-card

function actionRedeem()
{
    $redirectFrom = ????;
    if ($redirectFrom === '/card/scan-card')
    {
        // some actions
    }
    else
        throw new ForbiddenHttpException('Must scan card!');
}

How do I get this $redirectFrom value with Yii2?

  • 写回答

1条回答 默认 最新

  • dongliuzi3410 2017-08-14 08:14
    关注

    You could use the remember() & previous() methods in yii\helpers\BaseUrl.

    function actionScanCard()
    {
        ...
        \yii\helpers\Url::remember();
        $this->redirect('/transaction/redeem');
        ...
    }
    

    in TransactionController (or other)

    function actionRedeem()
    {
        $url = \yii\helpers\Url::previous();
        if($url === Url::to('card/scan-card')) {
            // some actions
        } else{}
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于vmprotect3.8.4虚拟文件一项
  • ¥20 C#调用虚拟键盘TabTip.exe
  • ¥15 Qt4代码实现下面的界面
  • ¥15 CCS离散化传递函数与仿真不一致
  • ¥15 prism提示我reinstall prism 如何解决
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用