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,

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

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