AnswerBun.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!

Related Questions

Magento 2 : create view table via setup script

2  Asked on February 15, 2021 by dominic-xigen

   

Get userid of the admin logged in magento 2 helper

1  Asked on February 12, 2021 by fahad-bashir

   

Product saving problem in admin control panel

1  Asked on February 12, 2021 by venkatesha

 

Print Address / Shipping Label For Magento 2

0  Asked on February 12, 2021 by naveen-sama

     

are the two codes same?

1  Asked on February 11, 2021 by hong-thng

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir