Tony's Blog

  1. Add an instance of “\Magento\Framework\UrlInterface” in your calss and use that:
  1. protected $urlBuider;
  2. public function __construct(
  3. ....
  4. \Magento\Framework\UrlInterface $urlBuilder,
  5. ....
  6. ) {
  7. ....
  8. $this->urlBuilder = $urlBuilder;
  9. ....
  10. }

Then you can use this:

  1. $url = $this->urlBuilder->getUrl('url/path/here', $paramsHere = array());

It works for me !!!