ques-7nf43Vl8

Search A2Z 24

Question : Calling getParams() in Magento2

X

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 2 Years ago

You can directly call inside phtml file like below

$params = $block->getRequest()->getParams(); 
See comments (0) | Comment
Answered 2 Years 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
loading...

×