If you want to redirect link with query string parameters using Magento ResultFactory, then you can use below script.
You can make a link with a query string using Magento\Framework\UrlInterface;
Here I have used that in the controller file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<?php namespace Vendername\Modulename\Controller\Index; use Magento\Framework\Controller\ResultFactory; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\View\Element\Messages; use Magento\Framework\DataObject; use Magento\Framework\UrlInterface; class Post extends Action { protected $_inlineTranslation; protected $_transportBuilder; protected $_scopeConfig; protected $_logLoggerInterface; protected $urlBuilder; protected $_attributeRepository; public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Psr\Log\LoggerInterface $loggerInterface, UrlInterface $urlBuilder, \Magento\Catalog\Model\Product\Attribute\Repository $AttributeRepository, array $data = [] ) { $this->_inlineTranslation = $inlineTranslation; $this->_transportBuilder = $transportBuilder; $this->_scopeConfig = $scopeConfig; $this->_logLoggerInterface = $loggerInterface; $this->messageManager = $context->getMessageManager(); $this->urlBuilder = $urlBuilder; $this->_attributeRepository = $AttributeRepository; parent::__construct($context); } public function execute() { $argument = array('q' => 'test'); $redirecturl = $this->urlBuilder->getUrl('set-your-redirect-path', ['_current' => true,'_use_rewrite' => true, '_query' => $argument]); return $this->resultRedirectFactory->create()->setUrl($redirecturl); } } |
Note: I have tried this code with Magento 2.3.5 version.
If you are facing error as per the below, Then...
I've to add custom CSS for particular store on checkout...
If we use the quote collectTotal() method in our custom...
If you want to set a different look for a...
I have recently faced an issue during CSV import as...