Search A2Z 24

Question : Calling getParams() in Magento2

How to achieve the below getParams() in Magento2?

$params = Mage::app()->getRequest()->getParams();
asked March 20, 2017

2 Answers

Dispalying 1 to 2 of 2 |

In controllers and blocks you have direct access to the request object:

$params = $this->getRequest()->getParams();

Anywhere else, you have to add \Magento\Framework\App\RequestInterface class as constructor parameter if it is not there yet, and assign it to $this->_request.
Example :

public function __construct(
    \Magento\Framework\App\RequestInterface $requestInterface
    $this->_request = $requestInterface;

Then you can use

$params =  $this->_request->getParams();
See comments (0) | Comment
Answered More than a year ago

You can directly call inside phtml file like below

$params = $block->getRequest()->getParams(); 
See comments (0) | Comment
Answered More than a year ago
Dispalying 1 to 2 of 2 |

Write your Answer write code <pre class="brush: xml">---code---</pre>

Login as a member to access answering block !! click-here

Reveal Modal Goodness

This is a default modal in all its glory, but any of the styles here can easily be changed in the CSS.

This is just a simple modal with the default styles, but any type of content can live in here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi quis sem vel enim eleifend tristique. Etiam tincidunt faucibus pharetra.