How to get url parameter : at this file app/code/Vendor/Module/Model/ResourceModel/Module/Grid/Collection.php

My Url is like this

i want to get ID in the collection.php how to achieve same, thanks,


With objectManager

$urlInterface = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Framework\UrlInterface');

With Factory Method

protected $_urlInterface;

protected $request;

public function __construct(
    \Magento\Framework\UrlInterface $urlInterface,
     \Magento\Framework\App\Request\Http $request,
) {
    $this->_urlInterface = $urlInterface;
    $this->request       = $request;

public function getUrlInterfaceData()
    echo $this->_urlInterface->getCurrentUrl();

    echo $this->_urlInterface->getUrl();

    echo $this->_urlInterface->getUrl('test/test2');

    echo $this->_urlInterface->getBaseUrl();

    echo $this->request->getParam('id'); //current url id parameter value

I hope it help..!!!

  • i am trying to get it in model Nov 21 '18 at 13:48
  • @AdarshShukla have you try above code ? Nov 21 '18 at 14:23
  • will echo $this->request->getParam('id'); work in resoursemodel/grid/collection Nov 22 '18 at 5:08
  • i am getting this error on admin panel wile using request->getParam('id'); in app/code/Vendor/Module/Model/ResourceModel/Module/Grid/Collection.php error is as following:- Missing required argument $model of Katalyst\Rfq\Model\ResourceModel\Rfqitems\Grid\Collection. Nov 22 '18 at 5:15
  • @AdarshShukla add you code here. Nov 22 '18 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.