I don't understand why but in many topics I see that to get and admin route url with secure key and parameter I only need to use :

$this->urlBuilder->getUrl('adminhtml/myroutename/mycontroller/myaction', array('myparam' => 'myvalue'))

and urlBuilder I a Magento\Framework\UrlInterface object.

But in front, I get this URL: http://mysite.lan/adminhtml/myroutename/mycontroller/myparam/myvalue/

And if I remove the adminhtml I get this URL: http://mysite.lan/myroutename/mycontroller/myaction/myparam/myvalue/

So how can I create a correct admin URL with the key and the params?

  • Where you use $this->urlBuilder(), In frontend or admin? – Prince Patel Oct 16 '17 at 13:22

If you are in an admin controller, you can just get the URL from the context (which is injected in the constructor):

$url = $this->context->getUrl();

$myUrl = $url->getUrl('adminhtml/myroutename/mycontroller/myaction', array('myparam' => 'myvalue'));

/This change with remove bracket/

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.