Magento2: How to generate admin url with secure key from a controller
From a controller you can simply use $this->getUrl('url/path/here', $paramsHere = array())
.
From anywhere else:
You need to add an instance of \Magento\Framework\UrlInterface
in your class and use that:
protected $urlBuider;
public function __construct(
....
\Magento\Framework\UrlInterface $urlBuilder,
....
) {
....
$this->urlBuilder = $urlBuilder;
....
}
Then you can use this:
$url = $this->urlBuilder->getUrl('url/path/here', $paramsHere = array());