浏览文章
文章信息
Magento2 外部URL跳转|Maegnto2 how to redirect to outsite
13349
示例:
<?php declare(strict_types=1); /** * 文件信息 * 作者:邹万才 * 网名:秋风雁飞(Aiweline) * 网站:www.aiweline.com/bbs.aiweline.com * 工具:PhpStorm * 日期:2021/6/5 * 时间:12:01 * 描述:此文件源码由Aiweline(秋枫雁飞)开发,请勿随意修改源码! */ namespace Aiweline\PaymentGateway\Controller\B; use Aiweline\PaymentGateway\Helper\Data; use Aiweline\PaymentGateway\Model\Session; use Magento\Framework\App\Action\Context; use Magento\Framework\App\ResponseInterface; use Magento\Framework\View\Result\PageFactory; class PayPage extends AbstractAction { /** * @var PageFactory */ private $pageFactory; function __construct( PageFactory $pageFactory, Data $helper, Context $context, Session $session ) { parent::__construct($helper, $context, $session); $this->pageFactory = $pageFactory; } /** * @inheritDoc */ public function execute() { $product = $this->initProduct(); if (!$product->getId()) { /**@var \Magento\Framework\Controller\Result\Redirect $redirect*/ $redirect = $this->_objectManager->get(\Magento\Framework\Controller\Result\Redirect::class.'Factory')->create(); $redirect->setUrl($this->getReferer() . '/' . Data::A_REBACK_URL.'?msg=403:Payment Gateway Error.'); return $redirect; } $resultPage = $this->pageFactory->create(); return $resultPage; } }