0

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

My Url is like this http://192.168.2.215/mtheme/admin/vendor_module/index/details/id/1/

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

1 Answer 1

2

With objectManager

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

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

8
  • i am trying to get it in model Commented Nov 21, 2018 at 13:48
  • @AdarshShukla have you try above code ? Commented Nov 21, 2018 at 14:23
  • will echo $this->request->getParam('id'); work in resoursemodel/grid/collection Commented Nov 22, 2018 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. Commented Nov 22, 2018 at 5:15
  • @AdarshShukla add you code here. Commented Nov 22, 2018 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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