TransWikia.com

How to add a parameter to 'request' when redirecting a page?

Magento Asked by Nuno Sousa on August 4, 2020

My code in Rooter.php:

$this->_response->setRedirect('customer/account/create');
$request->setDispatched(true);
$request->setParam('nickname', $request->getPathInfo());
return $this->actionFactory->create(MagentoFrameworkAppActionRedirect::class);

My code in register.phtml:

$sponsor = $block->getRequest()->getParam('nickname');

$sponsor returns null because params: array(0)

One Answer

You have already done the something at your code

setParam('nickname', $request->getPathInfo())

Using setParam() you can pass a parameter to the controller.

Suppose, You have added another parameter like

setParam('myname', 'Nuno Sousa')

At Controller's Action file' you get this myname field value by using below code:

$this->getRequest()->getParam('myname')

At block you can get value by $this->getRequest()->getParam('myname') and phtml $block->getRequest()->getParam('myname')

Answered by Amit Bera on August 4, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP